Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make it so that you can't get the item multiple times?

Asked by
wddfrt 21
4 years ago

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

Log in to vote
1
Answered by 4 years ago

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.

0
Thank you! this is exactly what I needed wddfrt 21 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
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.

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. wddfrt 21 — 4y
0
Anyhow, thank you for going out of your way to answer my question. wddfrt 21 — 4y
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. SilentsReplacement 468 — 4y
0
Also you were correct. The if statement on the last was useless but now it's not. SilentsReplacement 468 — 4y

Answer this question