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

Can't figure out how to run a function on the click of a TextButton?

Ok so when I click the text button I want the model "Ship" in Lighting to clone, and go into Workspace. I can't figure out how to run the function when I click the button!Heres my script!

function onClick()
	local ship = game.Lighting.Ship:Clone()
	ship.Name = "TheShip"
	ship.Parent = game.Workspace
end

So when I'd add onClick() to run the function, what would I write?

1 answer

If you want the function to be called whenever the GUI is clicked, just connect() it to the MouseButton1Down event.

script.Parent.MouseButton1Down:connect(onClick)

On a side note, you really should store objects in ServerStorage or ReplicatedStorage instead of Lighting.

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