Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How To End Function After Activated Once?

So this script lets a player place a table after they click the script.Parent but when you select it, you can place all the tables you want. How can I make it so that you only can place one table when you click the parent?

grid = 3
grid2 = 6
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()

mouse.Button1Down:connect(function()
	local Spawn = game.Workspace.start
	local Pos =(Vector3.new((mouse.Hit.p.X+grid) - (mouse.Hit.p.X+grid)%grid2, (Spawn.Position.Y+0.5), (mouse.Hit.p.Z+grid) - (mouse.Hit.p.Z+grid)%grid2)) --tree stump
    local part = game.ReplicatedStorage.Table:Clone()
    part.Position = Pos
    part.Parent = game.Workspace
	print("Table Placed")
end)

1 answer

✓ Accepted answer

Create a new function and put the intended function of what would happen when clicking on the script.Parent. Now, create a new variable and set it to zero. Inside the function where you would click, create an if statement. If the Variable equals zero, then set it to one and call the function, which is meant to create a new table. However, if it's already equal to one, then end mouseclick function and do not call the function that would place a table

If you need further help or an example, please tell me.

2 comments

0

Thank you for this answer, what I did was make a local value equaling zero and then when the function is ran, it adds one to it and if the value ~= 0 then the script ends but it seems to not work. Most likely I did something wrong. Could you provide a small example?

0

Anyways, I found another solution to my dilemma but I will accept this anyways because you put effort into it :)

This discussion is preserved as it was. New answers, comments, and votes are closed.