Apologies for vague title, couldn’t think of a way to describe it in a title. I am currently developing a building system, and it is going great! Issue is, once the player starts to be able to click to place, it will go on forever and my walnut brain can’t figure out a way to stop this once it has been clicked once and make it go back
Local Script in the GUI
local ScreenGui = script.Parent
local function ConnectDescendant(Descendant)
if Descendant:IsA("TextButton") or Descendant:IsA("ImageButton") then
Descendant.MouseButton1Down:Connect(function()
local name = Descendant.Name
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
mouse.Button1Up:Connect(function()
local hit = mouse.Hit
game:GetService("ReplicatedStorage").PlaceEvent:FireServer(name, hit)
end)
end)
end
end
ScreenGui.DescendantAdded:Connect(ConnectDescendant)
for _, Descendant in ScreenGui:GetDescendants() do
ConnectDescendant(Descendant)
end
Script in ServerScriptService
local RemoteEvent = game:GetService('ReplicatedStorage').PlaceEvent
local function ServerEvent(player, name, hit)
local item = game:GetService("ServerStorage"):FindFirstChild(name)
local clone = item:Clone()
clone.Parent = game.Workspace
clone:SetPrimaryPartCFrame(hit)
end
RemoteEvent.OnServerEvent:Connect(ServerEvent)