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

ClickDetector not working but TextButton works?

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

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)

1 comment

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

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.

5 comments

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.

0

So what exactly do you want? When the click function is fired you want to configure the text button?

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.

0

Oh then just use the function I used in my answer, that means the function is fired whenever the player clicks on "Screen"

0

Tried that. Clicking the part just does nothing. No errors, no GUI changes, no variables. Nothing. TextButton works just fine however!

oof'n image

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

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