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

How can i detect the player if he has the tool?

Example , If the player has a LeverHolder, and He clicked on the broken lever, the broken lever will be fix and his level in his inventory will dissapear? can anyone help?

I also tried

script.Parent.ClickDetector.MouseClick:Connect(function()
	local player = game.Players.LocalPlayer
	
	player.Backpack:WaitForChild("Lever"):Destroy()
end)

1 answer

✓ Accepted answer

We can simply look inside the player's backpack to that certain instance.

Assuming this is being done through a clickdetector.

part.ClickDetector.MouseClick:Connect(function(plr)
	if plr.Backpack:FindFirstChild("LeverHolder") then
		--dostuff
	end
end)

What if this was a Tool? The player could equip it and it would no longer be in the Backpack, now we have to check if it is in the character.

part.ClickDetector.MouseClick:Connect(function(plr)
	if plr.Backpack:FindFirstChild("LeverHolder") or plr.Character:FindFirstChild("LeverHolder") 
		--dostuff
	end
end)

2 comments

0

great answer

0

Thanks so much!

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