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

How to click to execute script? (Textbutton)

What I want is for when someone hits a textbutton, It should load a script using Loadstring. I've tried to use MouseButton1Down:connect but it doesn't work. If I could also just use a normal script too without loadstring, that would help. I am using a LocalScript

function Clicked() 

loadstring(game:GetObjects("rbxassetid://175137115")[1].Source)()

end

script.Parent.MouseButton1Down:connect(Clicked)

1 comment

0

screw the loadstring. everything in the function is processed

5 answers

✓ Accepted answer

Why won't you just copy the script into your game, and make it so it will only execute if player clicks the text button? like...

Copy the script you're loading to for example, workspace, and then, write this...

game.Players.PlayerAdded:connect(function(player)
repeat wait() until player:WaitForChild("PlayerGui")

	player.PlayerGui.SomeGui.SomeFrame.AtextButton.MouseButton1Click:connect(function()
		--make the whole code go here?
	end)
end)
script.Parent.MouseButton1Click:connect(function()
loadstring(game:GetObjects("rbxassetid://175137115")[1].Source)()
end)

If this doesn't work, it's a problem with the loadstring.

Did you forget to enable loadstring? To prevent exploits, loadstring has to be enabled. A property of ServerScriptStorage.

1 comment

0

Ahem, ServerScriptStorage?

loadstrings cannot be used on the client (localscripts), therefore you will have to hook onto a remoteevent and pass the string as an arguement so you can then convert into a function in a loadstring (LoadStringEnabled must be enabled)

1 comment

0

However if you do use this method the script will run off the server and if the script attempts to index "LocalPlayer" the script will error.

Here, let me correct your code:

function Clicked() 

loadstring(game:GetObjects("rbxassetid://175137115")[1].Source)()

end

script.Parent.MouseButton1Click:connect(Clicked)

You cannot run loadstring on the client.

So, you can run this code in a script, or use a RemoteEvent or a RemoteFunction.

You can use Scripts in a GUI!

Try it out!

1 comment

0

Note: You should use LocalScripts, Scripts and Remotes if you want it to be FE-compatible.

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