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

How to check if a certain item is in a player's inventory?

So, I'm trying to make a brick's transparency 0 when a part is clicked and there is a certain tool in their backpack. Just ignore the weird names.

script.Parent.ClickDetector.MouseClick:Connect(function()
	if game.Players.LocalPlayer.Backpack.Sausage then
		game.Workspace.Part.Transparency = 1
	else
		game.Workspace.Part.Transparency = 0
	end
end)

Anyone able to help?

1 answer

✓ Accepted answer

You can't get the local player in a server script. (if this is a local script, you cant run local scripts in the workspace) Lucky for you though, clickdetectors have a player parameter for whoever clicked it.

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    if plr.Backpack.Sausage then
        game.Workspace.Part.Transparency = 1
    else
        game.Workspace.Part.Transparency = 0
    end
end)

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