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

(ANSWERED) How come my script only gives the player the item ONCE?

#Introduction Hi there! I made a script that gives a player an item when they click it, and it works. But it only gives them the item once and then stops working. Here is my script:

local tool = game.ServerStorage.Card
local klone = tool:clone
script.Parent.ClickDetector.MouseClick:connect (function(plr)
if klone.Parent ~= plr.Backpack then
klone.Parent = plr.Backpack
else
end
end)

#Conclusion Can somebody help me?

2 comments

0

I mean if they already have the item, it won't give them another one right? Unless your talking about if the player has the item, looses the item, and then tries to get the item back. If thats the case, idk ;-;.

0

Put local Klone inside the function. That should fix it

2 answers

✓ Accepted answer

So in this script, there is an if-then statement that checks if you currently have the item. If you remove the statement, then it should fix it.

local tool = game.ServerStorage.Card
local klone = tool:clone
script.Parent.ClickDetector.MouseClick:connect (function(plr)
klone.Parent = plr.Backpack
else
end)

2 comments

0

Also it only clones klone once so it probably needs to have local klone INSIDE the function so it clones every time they clicks it

0

try doing tool:Clone() instead of tool:clone

Here you go.

script.Parent.ClickDetector.MouseClick:connect (function(plr)
local tool = game.ServerStorage.Card:Clone()
if tool.Parent ~= plr.Backpack then
tool.Parent = plr.Backpack
else
tool:Destroy()
warn("This player already has the tool!")
return
end
end)

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