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

Why is my ClickDetector script not working correctly?

Here's the script:

local b = game.Workspace.jj
local db = false



function check(hit)
	local human = hit.Parent:FindFirstChild("Humanoid")
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not db then
		if human then
			
			db = true
			
			human.WalkSpeed = 0
			game.Workspace.Board2.SurfaceGui.TextBox.Text = ("Wrong!")
			wait(3)
			player:LoadCharacter()
			game.Workspace.Board2.SurfaceGui.TextBox.Text = ("Click the most expensive hat in this room.")
		end
	end
end

b.ClickDetector:connect(check)

Basically, I want it that if I click the block(jj) then it will freeze my character, proceed to change the text and finally, re-spawn me. Any suggestions?

1 answer

✓ Accepted answer

Looks like you took a touched event and tried adding a ClickDetector event. You forgot the event. Also, MouseClick will return the player, so you don't need to manually get the player like in a Touched event.

local b = game.Workspace.jj
local db = false



function check(player)
	if not db then
		db = true
		local Humanoid = player.Character:WaitForChild("Humanoid")
		Humanoid.WalkSpeed = 0
		game.Workspace.Board2.SurfaceGui.TextBox.Text = ("Wrong!")
		wait(3)
		player:LoadCharacter()
		game.Workspace.Board2.SurfaceGui.TextBox.Text = ("Click the most expensive hat in this room.")
		--db = false -- Add this if you want the debounce to reset
	end
end

b.ClickDetector.MouseClick:Connect(check)--Added event MouseClick

Good Luck!

If I helped, please don't forget to accept my answer!

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