Advertisement
Guest User

Rbx_1

a guest
Jan 1st, 2025
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | Spirit | 0 0
  1. --Spawn Tower Script (Server)
  2. local getTower = game.ReplicatedStorage.GetTower
  3.  
  4. game.ReplicatedStorage.SpawnTowerEvent.OnServerEvent:Connect(function(plr, index, pos)
  5.    
  6.     local towerToPlace = getTower(index):Clone()
  7.     -- ^ returning error, "attempt to call an instance value"
  8.        
  9.     if towerToPlace ~= nil then
  10.         towerToPlace:MoveTo(pos)
  11.  
  12.         towerToPlace.Parent = workspace.Map.Towers
  13.     end
  14. end)
  15.  
  16. --Get Tower Script (Module)
  17. local repStorage = game:GetService("ReplicatedStorage")
  18. local towers = repStorage.Towers
  19.  
  20. local function GetTower(index)
  21.     if index == 10001 then
  22.         print(towers.Boxer)
  23.         return towers.Boxer
  24.     end
  25. end
  26.  
  27. return GetTower
  28.  
  29. --Place Script (Local)
  30. local key = game:GetService("UserInputService")
  31. local replicatedStorage = game:GetService("ReplicatedStorage")
  32. local getTower = require(replicatedStorage.GetTower)
  33. local towerInHand = false
  34. local towerOneIndex = 10001
  35. local currentIndex
  36. local player = game.Players.LocalPlayer
  37. local mouse = player:GetMouse()
  38. local tower = nil
  39.  
  40. mouse.TargetFilter = workspace.Map.TowersToPlace
  41.  
  42. mouse.Button1Down:Connect(function()
  43.     if tower ~= nil and towerInHand then
  44.         replicatedStorage.SpawnTowerEvent:FireServer(currentIndex, mouse.Hit.Position)
  45.     end
  46. end)
  47.  
  48.  
  49. key.InputBegan:Connect(function(input)
  50.    
  51.     if input.KeyCode == Enum.KeyCode.One then
  52.         towerInHand = true
  53.        
  54.         tower = getTower(towerOneIndex):Clone()
  55.        
  56.         currentIndex = towerOneIndex
  57.        
  58.         tower.Parent = workspace.Map.TowersToPlace
  59.        
  60.         mouse.Move:Connect(function()
  61.             print("moved")
  62.             if towerInHand then
  63.                 tower:MoveTo(mouse.Hit.Position)
  64.             end
  65.  
  66.         end)
  67.     end
  68.    
  69. end)
Tags: lua
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement