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

How To Run The Click & Selected Functions When textbutton Is Clicked?

So I have spent a great deal of time working on perfecting this tool. Now I am wanting to change it so that the same effect of the tool. How can I easily convert the functions so that the rest of the script is triggered when the TextButton is clicked?

local frame = script.Parent.Parent.Parent:WaitForChild('Items')
script.Parent.MouseButton1Click:connect(function()
frame.Visible = not frame.Visible
end)

tool = script.Parent
grid = 3
grid2 = 6


function click(mouse)  --- This line and below are what I need to know how to convert
	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("Tree Placed")
end

function selected(mouse)
    mouse.Button1Down:connect(function () click(mouse) end)
	wait(2)
end

tool.Equipped:connect(selected)

2 comments

0

you mean running the click and selected functions when the textbutton (Script.Parent)? is clicked??

0

Yes

1 answer

✓ Accepted answer

put click() and selected() inside

script.Parent.MouseButton1Click:Connect(function()
frame.Visible = not frame.Visible
end)

like

script.Parent.MouseButton1Click:Connect(function()
frame.Visible = not frame.Visible
click()
selected()
end)

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