Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How To End Function After Activated Once?

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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.

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? BunnyFilms1 297 — 7y
0
Anyways, I found another solution to my dilemma but I will accept this anyways because you put effort into it :) BunnyFilms1 297 — 7y
Ad

Answer this question