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.
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.