Can anyone please solve this, it is in startergui then shop (a screen gui) , then frame, then main (a frame) then item 1 (contains script with code 1), item 2 (contains script with code 2), a serperator ( a frame), a textbutton, and a title. script 3 is in the workspace.
1. script.Parent.MouseButton1Click:connect(function() local RS = game:GetService("ReplicatedStorage") local item = RS:WaitForChild("Sword") local price = 100 local player = game.Players.LocalPlayer local stats = player:WaitForChild("leaderstats") if stats.Cash.Value == price then stats.Cash.Value = stats.Cash.Value - price local cloned = item:Clone() local cloned2 = item:Clone() cloned2.Parent = player.Backpack cloned.Parent = player.StarterGear end end)
2. script.Parent.MouseButton1Click:connect(function() local RS = game:GetService("ReplicatedStorage") local item = RS:WaitForChild("Rocket Launcher") local price = 500 local player = game.Players.LocalPlayer local stats = player:WaitForChild("leaderstats") if stats.Cash.Value == price then stats.Cash.Value = stats.Cash.Value - price local cloned = item:Clone() local cloned2 = item:Clone() cloned2.Parent = player.Backpack cloned.Parent = player.StarterGear end end)3. print("Hello world!") game.Players.ChildAdded:connect(function(player) local stats = Instance.new("Model",player) stats.Name="leaderstats" local money = Instance.new("IntValue",stats) money.Name="Cash" money.Value=30 -- Change Your Starting Money end)
I don't know if you are going to be able to obtain more cash in game, but currently your default money seems not enough to purchase any of those items. If that is the case, make default cash more higher or make a system to give yourself more cash so you can have enough cash to buy item.
The error I found in the script is that I think you can't buy a item even if you have more money than it's price. That is because you are using if stats.Cash.Value == price then
which checks if you have exact same amount of money as price, then purchase instead of checking if you have more cash than the price of item.
All you need to do is to replace " ==" (equal to) to ">=" (greater than, or equal to) so you can buy the item if you have same or more cash than price.