Function runs 1 more time, every time it's called. Any idea?
Hello! This is my first question so point out anything I'm doing wrong.
I am attempting to make a game similar to Tower Defense Simulator. This is what I have for the tower placement script
LocalScript (in StarterGui)
04 | local player = game.Players.LocalPlayer |
05 | local event = game.ReplicatedStorage.Remotes:WaitForChild( 'PlaceTower' ) |
06 | local button = script.Parent |
07 | local Highlight = game.Workspace.Highlight |
08 | local UIS = game:GetService( 'UserInputService' ) |
15 | local mouse = player:GetMouse() |
16 | mouse.TargetFilter = Highlight |
19 | local function place () |
21 | Highlight.Parent = game.Workspace |
22 | UIS.InputBegan:Connect( function (input) |
23 | if input.UserInputType = = Enum.UserInputType.MouseButton 1 and using then |
27 | local HumanoidCFrame = Highlight:FindFirstChild( 'HumanoidRootPart' ).CFrame |
28 | event:FireServer(HumanoidCFrame, 'Tower1' ) |
30 | Highlight.Parent = nil |
36 | Highlight.HumanoidRootPart.CFrame = CFrame.new(mouse.Hit.p.X, mouse.Hit.p.Y + 1.315 , mouse.Hit.p.Z) |
42 | button.MouseButton 1 Up:Connect( function () |
Normal Script (in server script service)
04 | local ReplicatedStorage = game.ReplicatedStorage |
05 | local placeTower = ReplicatedStorage.Remotes:WaitForChild( 'PlaceTower' ) |
08 | local function placeTowerFunction(plr, cframe, tower) |
10 | local Tower = ReplicatedStorage:WaitForChild(tower) |
11 | local TowerClone = Tower:Clone() |
12 | TowerClone.Parent = game.Workspace |
13 | TowerClone.HumanoidRootPart.CFrame = cframe |
17 | placeTower.OnServerEvent:Connect(placeTowerFunction) |
Basically, I would place one tower, and one tower would place. After that, I would place a second tower and two towers would place in the same spot, then 3, 4, and so on.
I would really appreciate any help, Thanks!