So I have a shop gui,then there is a buy button,what i want it to do is that i want the player to buy a tool,then the player will not be able to buy it again.It will cost the in game currency,so i do not want it to be in a games form.However it doesn't work.I don't know what is wrong but i tried :FindFirstChild
and still did not work
There was also NO output error
local plr = game.Players.LocalPlayer local Cloud = game.ReplicatedStorage["Flying Cloud"] local button = script.Parent button.MouseButton1Click:Connect(function() if plr.leaderstats.Scikoins.Value == 100 or plr.leaderstats.Scikoins.Value >= 100 then plr.leaderstats.Scikoins.Value = plr.leaderstats.Scikoins.Value - 100 Cloud:Clone().Parent = plr.Backpack wait(2) warn(plr.Name.."has bought a cloud") else warn(plr.Name.."has not enough scikoins") if plr.Backpack:FindFirstChild("Flying Cloud") then warn(plr.Name.."already has a cloud") end end end)
The logic to your script is wrong. Look at your last if statement, it's inside the else. This means that if statement can only run if plr does not have enough money AND already has the item.
local plr = game.Players.LocalPlayer local Cloud = game.ReplicatedStorage["Flying Cloud"] local button = script.Parent button.MouseButton1Click:Connect(function() if plr.leaderstats.Scikoins.Value == 100 or plr.leaderstats.Scikoins.Value >= 100 then if plr.Backpack:FindFirstChild("Flying Cloud") then warn(plr.Name.."already has a cloud") else plr.leaderstats.Scikoins.Value = plr.leaderstats.Scikoins.Value - 100 Cloud:Clone().Parent = plr.Backpack wait(2) warn(plr.Name.."has bought a cloud") end else warn(plr.Name.."has not enough scikoins") end end)
Remember that your code checks from top to bottom, and left to right. I thinks that's the main problem (I didn't check it though).
local plr = game.Players.LocalPlayer local Cloud = game.ReplicatedStorage["Flying Cloud"] local button = script.Parent button.MouseButton1Click:Connect(function() if plr.Backpack:FindFirstChild("Flying Cloud") then warn(plr.Name.."already has a cloud") return -- returns the function end if plr.leaderstats.Scikoins.Value == 100 or plr.leaderstats.Scikoins.Value >= 100 then plr.leaderstats.Scikoins.Value = plr.leaderstats.Scikoins.Value - 100 Cloud:Clone().Parent = plr.Backpack wait(2) warn(plr.Name.."has bought a cloud") else warn(plr.Name.."has not enough scikoins") -- if plr.Backpack:FindFirstChild("Flying Cloud") then -- switch this so it is above the buy system and the script reads it first before subtracting money from the player -- warn(plr.Name.."already has a cloud") -- end end end)