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

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

Asked by
Slatryte 104
5 years ago
Edited 5 years ago

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?

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 ;-;. fighterkirbyzx 102 — 5y
0
Put local Klone inside the function. That should fix it fighterkirbyzx 102 — 5y

2 answers

Log in to vote
0
Answered by
nap516 87
5 years ago
Edited 5 years ago

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)
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 fighterkirbyzx 102 — 5y
0
try doing tool:Clone() instead of tool:clone User_3805 6 — 5y
Ad
Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
5 years ago
Edited 5 years ago

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)

Answer this question