ClickDetector Doesn't work after player dies/respawns on a local part

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to achieve when you click on a part, I want it to disappear, and it works perfectly fine, though it is only for the local player. So if a player clicks on it, it will disappear for the player, but not for the others until they have also clicked on it.

  2. What is the issue? Well, the issue I am having is, when you respawn, the clickdetector will not work anymore and it gives me a warning: Infinite yield possible on ‘ReplicatedStorage:WaitForChild(“Clicks”)’. Also that means if the clickdetector doesn’t work, it won’t disappear.

  3. What solutions have you tried so far? I have looked up on the internet, also tried by myself to fix it but it won’t work.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- Code : 
local Clicks = game.ReplicatedStorage:WaitForChild("Clicks")
local clickValues = game.ReplicatedStorage.clickValues
Clicks:Clone()
Clicks.Parent = game.Workspace.CurrentCamera

local function onClick(click)
	
	clickValues.Value += 1
	click:Destroy()
	
	if clickValues.Value == 1 then
		print("Number 01")
	elseif clickValues.Value == 2 then
		print("Number 02")
	else
		warn("Invalid Number")
	end
	
end

for _, click in pairs(Clicks:GetChildren()) do
	local ClickDetector = click:FindFirstChild("ClickDetector")
	if ClickDetector then
		ClickDetector.MouseClick:Connect(function()
			onClick(click)
		end)
	end
end

Since you are parenting the Click objects to the camera when the player dies they will be deleted. I recommend putting this script into the StarterPlayerScripts so it doesn’t run multiple times.

THANKS! IT WORKED! I spent so long trying to figure this out! :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.