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

ClickDetector not working but TextButton works?

Asked by 6 years ago

I have a script which looks like this:

script.Parent.MouseButton1Click:connect(function()
        --code is inserted here
end)

I am wanting to change the script so that, instead of Script.Parent (a TextButton) triggering the code, 'game.Workspace.Screen' (clickDetector) triggers the code. I have:

game.Workspace.Screen.ClickDetector.MouseClick:connect(function()
           --same code inserted here
end)

Upon clicking, nothing is happening. As soon as I reverted it to the TextButton script, it worked fine. Any help? No errors are outputted.

3 answers

Log in to vote
0
Answered by
Griffi0n 315 Moderation Voter
6 years ago
Edited 6 years ago

Why aren't you using script.Parent because if you were using a local script that's probably the problem: The player that clicked the object is passed as the first param of the MouseClick function

script.Parent.ClickDetector.MouseClick:connect(function(player)
    print(player.Name.." clicked the button.")
end)
0
I didn't use script.parent because 'screen' is not the parent of the script. I can't move the script either because the whole of my code relies on script.parent as it's a GUI. *sigh* OneFatDollar 2 — 6y
Ad
Log in to vote
0
Answered by
65225 80
6 years ago
Edited 6 years ago

Ok, by the information given you want a button in workspace, and when clicked, a gui will be modified? Well, you can use players' PlayerGui. Like so:

game.Workspace.Screen.ClickDetector.MouseClick:connect(function(plr)
    plr.PlayerGui.ScreenGui.TextButton -- etc
end)

Please inform me if I am wrong as I would like to at least try to help out. If this answered your problem, please accept my answer.

0
Basically, I just want to replace my script so that instead of the TextButton making it happen, game.Workspace.Screen makes it happen (a brick with clickDetector). The brick is not doing anything when clicked, but the TextButton does. OneFatDollar 2 — 6y
0
So what exactly do you want? When the click function is fired you want to configure the text button? 65225 80 — 6y
0
I am making a game. I have a whole script set up to randomise lots of different things, setting up variables, changing texts on a GUI etc as it is all part of the game. Currently, when I click the TextButton, all this happens. All the variables are defined and the GUI is changed. However, I need it so that when the player clicks a part called Screen, everything happens instead of the TextButton. OneFatDollar 2 — 6y
0
Oh then just use the function I used in my answer, that means the function is fired whenever the player clicks on "Screen" 65225 80 — 6y
0
Tried that. Clicking the part just does nothing. No errors, no GUI changes, no variables. Nothing. TextButton works just fine however! OneFatDollar 2 — 6y
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

oof'n image

Well there you go, I guess it has to be handed with a script. Use RemoteEvents

Answer this question