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

How do I make my brick give me more than one tool?

Asked by
OhNope 6
5 years ago

Hi, I am creating a script which is activated once a player clicks on the brick. The brick gives a tool called 'Beans'. This works fine when I test it, however, when I click the brick again, it does not give me another 'Beans'. Also, when I die and try to collect the beans I get an error in the output saying 'The Parent property of Beans is locked, current parent: NULL, new parent Backpack'. I'm not too sure how to fix that. I would like it so that the player can have as many 'Beans' as they want. I would appreciate it if someone would tell me where I am going wrong. This is the script I have:

local tool = game.ServerStorage:WaitForChild("Beans")
local IGBeans = game.Workspace.IGBeans
local IGBeansD = IGBeans.Decal
local clone = tool:Clone()

IGBeans.ClickDetector.MouseClick:connect(function(plr)
clone.Parent = plr.Backpack
IGBeans.Transparency = 1
IGBeans.Decal.Transparency = 1

wait(240)

IGBeans.Transparency = 0
IGBeans.Decal.Transparency = 0
end)

So I have made it so that the beans disappear when collected, but after 240 seconds I would like the player to be able to collect them again, even if they already have the tool. Thanks in advance.

0
Make another part with the same script, place both parts into each other, or make half of it one part, and half the other part (size) TheJBoi -5 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

This is because you are cloning the tool once and then parenting it when the player clicks. So, the next time a player clicks, the tool is still the one that was in the player.

local clone = tool:Clone()
clone.Parent = plr.Backpack

You need to reclone it, Like so:

local tool = game.ServerStorage:WaitForChild("Beans")
local IGBeans = game.Workspace.IGBeans
local IGBeansD = IGBeans.Decal
local clone = tool:Clone()

IGBeans.ClickDetector.MouseClick:connect(function(plr)
    clone.Parent = plr.Backpack
    clone = tool:Clone()
    IGBeans.Transparency = 1
    IGBeans.Decal.Transparency = 1

    wait(240)

    IGBeans.Transparency = 0
    IGBeans.Decal.Transparency = 0
end)

To allow collecting every 240 seconds, you could use a debounce https://www.robloxdev.com/articles/Debounce

Please accept my answer if it helped you, but comment if I didn't solve your question or you need more help.

0
yea chesse20 -20 — 5y
0
Works just how I want it now, thanks a lot! OhNope 6 — 5y
Ad

Answer this question