I am making a build script, in which the script is looking to see whether or not the part the player is trying to place is too close to another. I am attempting this with 2 events and changing a variable to stop placement. Here are the building scripts.

local Plr = script.Parent.Parent.Parent.Parent game.ReplicatedStorage.GoodBuild.OnServerEvent:Connect(function(player, partPos) print (partPos) local newPart = Instance.new("Part") local Number = Instance.new("IntValue",newPart) local lvl = Instance.new("IntValue",newPart) local ScriptClone = game.ReplicatedStorage.ClickScript:Clone() local ScriptClone2 = game.ReplicatedStorage.ClosenessScript:Clone() local ClickDetector = Instance.new("ClickDetector", newPart) Number.Value = Plr.PlayerGui.Values.NumberOfTowers.Value + 1 Number.Name = "TowerNumber" lvl.Value = 0 lvl.Name = "TowerLvl" ScriptClone.Parent = newPart ScriptClone2.Parent = newPart Plr.PlayerGui.Values.NumberOfTowers.Value = Plr.PlayerGui.Values.NumberOfTowers.Value + 1 newPart.Parent = workspace newPart.Name = "Troop" newPart.Position = partPos newPart.Anchored = true end)

local Plr = script.Parent.Parent.Parent.Parent game.ReplicatedStorage.BadBuild.OnServerEvent:Connect(function() local GuiClone = game.ReplicatedStorage.BadBuildGui:Clone() GuiClone.Parent = Plr.PlayerGui wait(3) GuiClone:Destroy() end)

game.ReplicatedStorage.Place.OnServerEvent:Connect(function(player, partPos) if (partPos - script.Parent.Position).Magnitude < 20 then game.ReplicatedStorage.BadBuild:FireServer() else game.ReplicatedStorage.GoodBuild:FireServer(partPos) end end)

1 comment

0

Could you put this into the Lua code block? It's the last icon that is blue and has "Lua" on it.