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

How to click to execute script? (Textbutton)

Asked by 7 years ago
Edited 7 years ago

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)
0
screw the loadstring. everything in the function is processed DrPredablox 153 — 7y

5 answers

Log in to vote
0
Answered by
OfcPedroo 396 Moderation Voter
7 years ago
Edited 7 years ago

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)
Ad
Log in to vote
0
Answered by 7 years ago
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.

Log in to vote
0
Answered by
H4X0MSYT 536 Moderation Voter
7 years ago

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

0
Ahem, ServerScriptStorage? xXprohax0r1337Xx 74 — 6y
Log in to vote
0
Answered by
fuj 49
7 years ago

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)

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. fuj 49 — 7y
Log in to vote
0
Answered by 6 years ago

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!

0
Note: You should use LocalScripts, Scripts and Remotes if you want it to be FE-compatible. xXprohax0r1337Xx 74 — 6y

Answer this question