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

ClickDetector opening a gui works in studio but NOT game?

So I recently put in a simple script where a clickdetector makes a GUI visible. But it does not work in game/online. this is the script: the script is inside the GUI, its a localscript not a server one

plr = game.Players.LocalPlayer
text = plr.PlayerGui.quirklabel.TextLabel
click = game.Workspace.Doctor.Head.ClickDetector

click.MouseClick:connect(function()
	if plr.check.Value == 1 then
		plr.check.Value = plr.check.Value -1
		text.Visible = true
		wait(2)
		text.Text = "Im here to show you your quirk results!"
		wait(2)
		text.Text = "And your quirk is..."
		wait(2)
		local quirk = math.random(1,20)
		if quirk == 1 then
			plr.Quirk.Value = "Super Regeneration"
			text.Text = "Super Regeneration!"
		end
		if quirk == 2 then
			plr.Quirk.Value = "Super Regeneration"
			text.Text = "Super Regeneration!"
		end
		if quirk == 3 then
			plr.Quirk.Value = "Super Regeneration"
			text.Text = "Super Regeneration!"
		end
		if quirk == 4 then
			plr.Quirk.Value = "Super Regeneration"
			text.Text = "Super Regeneration!"
		end
		if quirk == 5 then
			plr.Quirk.Value = "Super Regeneration"
			text.Text = "Super Regeneration!"
			end
			if quirk == 6 then
			plr.Quirk.Value = "Transparency"
			text.Text = "Transparency!"
		end
		if quirk == 7 then
			plr.Quirk.Value = "Transparency"
			text.Text = "Transparency!"
		end
		if quirk == 8 then
			plr.Quirk.Value = "Transparency"
			text.Text = "Transparency!"
		end
		if quirk == 9 then
			plr.Quirk.Value = "Transparency"
			text.Text = "Transparency!"
		end
		if quirk == 10 then
			plr.Quirk.Value = "Transparency"
			text.Text = "Transparency!"
			end
				if quirk == 11 then
			plr.Quirk.Value = "Half Hot Half Cold"
			text.Text = "Half Hot Half Cold!"
		end
		if quirk == 12 then
			plr.Quirk.Value = "Half Hot Half Cold"
			text.Text = "Half Hot Half Cold!"
		end
		if quirk == 13 then
			plr.Quirk.Value = "Half Hot Half Cold"
			text.Text = "Half Hot Half Cold!"
		end
						if quirk == 14 then
			plr.Quirk.Value = "Explosion"
			text.Text = "Explosion!"
		end
		if quirk == 15 then
			plr.Quirk.Value = "Explosion"
			text.Text = "Explosion!"
		end
		if quirk == 16 then
			plr.Quirk.Value = "Explosion"
			text.Text = "Explosion!"
		end
							if quirk == 17 then
			plr.Quirk.Value = "Electrification"
			text.Text = "Electrification!"
		end
		if quirk == 18 then
			plr.Quirk.Value = "Electrification"
			text.Text = "Electrification!"
		end
		if quirk == 19 then
			plr.Quirk.Value = "Electrification"
			text.Text = "Electrification!"
			end
			if quirk == 20 then
				plr.Quirk.Value = "One For All"
				text.Text = "One For All!"
			end
			wait(0.8)
			plr.Character.Humanoid.Health = 0
			text.Visible = false
end
end)

11 comments

0

is it a local script or server

0

are you using FE?

0

It's a localscript, and Im not using FE

0

Can you check if the event is being ran by adding in some prints.

0

Just did, and its not being ran

0

I used to have problems with click detectors working in studio but not in game as well. Its pretty frustrating!

0

I think this would fix it: Instead of using connect , use Connect becuase connect is depracated.

0

what?? I thought :Connect was deprecated!

0

I think click detectors can only be activated with server scripts

0

It did not work, I tried server scripts, local scripts, and :Connect

0

try using a text button instead of a click detector if you're using a Gui

2 answers

Try making all ":connect" into ":Connect"

3 comments

0

Lol, you making a hero academia game? Cool

0

so I just make the c capitalized?

0

It didn't work.

code should be in a server script in the head of the doctor with the click detector like this . Code:

local click = script.Parent:WaitForChild("ClickDetector")

click.MouseClick:Connect(function(plr) --plr is the player who clicked, its the only way to do it in server scripts
	local text = plr.PlayerGui.quirklabel.TextLabel
	if plr.check.Value == 1 then
		--code
	end
end)

1 comment

0

It still only works in Studio. And I don't know why, theres no F9 errors.

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