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 make it so that you can't get the item multiple times?

I need the script only to run if the item (Black Glowstick) is not in their inventory

local clickdetector = script.Parent.ClickDetector

clickdetector.MouseClick:Connect(function(player)

    game.ServerStorage["Black Glowstick"]:Clone().Parent = player.Backpack

end)

2 answers

✓ Accepted answer

You can check with :FindFirstChild() if the item exists in the backpack. However make sure to also check if the item exists within the player his character. Equipped tools are moved to the character so they can be shown in the workspace.

1 comment

0

Thank you! this is exactly what I needed

local clickdetector = script.Parent.ClickDetector

clickdetector.MouseClick:Connect(function(player)
	
        if player.Backpack:FindFirstChild("Black Glowstick") or player.Character:FindFirstChild("Black Glowstick") then
    return end

    game.ServerStorage["Black Glowstick"]:Clone().Parent = player.Backpack

end)

Basically, it checks if the player has the item already and also checks if the player has equipped the item, it won't give the item to the player again.

4 comments

0

Thank you for your input, but i'm pretty sure it is wrong. When you check if the player has the item in their inventory or in their character, you put an and instead of a or. This means that they have to have the item in their Backpack and character at the same time. The second thing is that you put the statement after the script gives the player the item, which renders the statement useless.

0

Anyhow, thank you for going out of your way to answer my question.

0

Sorry about that, I fixed my script because It actually checked if the player had the item and equipped. Now it checks if the player has the item or equipped.

0

Also you were correct. The if statement on the last was useless but now it's not.

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