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:

1local tool = game.ServerStorage.Card
2local klone = tool:clone
3script.Parent.ClickDetector.MouseClick:connect (function(plr)
4if klone.Parent ~= plr.Backpack then
5klone.Parent = plr.Backpack
6else
7end
8end)

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.

1local tool = game.ServerStorage.Card
2local klone = tool:clone
3script.Parent.ClickDetector.MouseClick:connect (function(plr)
4klone.Parent = plr.Backpack
5else
6end)
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.

01script.Parent.ClickDetector.MouseClick:connect (function(plr)
02local tool = game.ServerStorage.Card:Clone()
03if tool.Parent ~= plr.Backpack then
04tool.Parent = plr.Backpack
05else
06tool:Destroy()
07warn("This player already has the tool!")
08return
09end
10end)

Answer this question