I'm making a simulator and for the shop, I had a bug where if you already had the tool you would not get it, But there is a saving tool, So when I rejoin I can buy the item again, I wrote some code and now it doesn't work anymore, Can anyone help me?
Here's my code:
player = script.Parent.Parent.Parent.Parent.Parent.Parent bucks = player.leaderstats.Bucks price = 25 tool = game:GetService("ReplicatedStorage"):FindFirstChild("Woods"):FindFirstChild("AmericaWood") infoFrame = script.Parent.Parent function buy() if bucks.Value >= price then if not player:FindFirstChild(tool) then script.Disabled = true else bucks.Value = bucks.Value - price local clone = tool:Clone() clone.Parent = player.Backpack local clone2 = tool:Clone() clone2.Parent = player.StarterGear player:WaitForChild("Backpack"):FindFirstChild("Wood"):Destroy() script.Disabled = true end end end script.Parent.MouseButton1Click:Connect(buy)
If anyone could help, Please help me, Thank you!
If I understand it correctly your script should disable it self if player already has the tool. Your conditions are broke.
player = script.Parent.Parent.Parent.Parent.Parent.Parent bucks = player.leaderstats.Bucks price = 25 tool = game:GetService("ReplicatedStorage"):FindFirstChild("Woods"):FindFirstChild("AmericaWood").Name infoFrame = script.Parent.Parent script.Parent.MouseButton1Click:Connect(function(plr) if bucks.Value >= price then if plr.Character:FindFirstChild(tool) or plr.Backpack:FindFirstChild(tool) then script.Disabled = true else bucks.Value = bucks.Value - price local clone = tool:Clone() clone.Parent = player.Backpack local clone2 = tool:Clone() clone2.Parent = player.StarterGear if player:WaitForChild("Backpack"):FindFirstChild("Wood") then player:WaitForChild("Backpack"):FindFirstChild("Wood"):Destroy() end script.Disabled = true end end end)
I dont understand why you are doing this stuff with disabling the script, and next time please say clearly what is not working, which error is popping up and what do you want us the script to do. I hope I understood you well, and I hope this helped. Have a good day.