I am making a weapon shop, and I have a successful script so that if you have the money for something on the GUI you can buy it. What I can't figure out is how to subtract the cost of that weapon from the player's amount. here's the script:
local plr = game.Players.LocalPlayer local replicatedstorage = game:GetService("ReplicatedStorage") script.Parent.MouseButton1Click:connect(function() if plr.leaderstats.Cash.Value >= 500 then replicatedstorage.MachineGun:Clone().Parent = plr.Backpack replicatedstorage.MachineGun:Clone().Parent = plr.StarterGear if script.Parent.MouseButton1Click and plr.leaderstats.Cash.Value >= 500 then game.plr.leaderstats.Cash.Value = game.plr.leaderstats.Cash.Value - 500 end end end)
Can you please tell me what's wrong, thank you very much!
https://www.roblox.com/library/184275443/UltraWorks-Shop-Creator-Pro-tools
Use that plugin it is a great way to make weapon shops buddy :]
Also for your question try doing this script
local plr = game.Players.LocalPlayer local replicatedstorage = game:GetService("ReplicatedStorage") script.Parent.MouseButton1Click:connect(function() if script.Parent.MouseButton1Click and plr.leaderstats.Cash.Value >= 500 then replicatedstorage.MachineGun:Clone().Parent = plr.Backpack replicatedstorage.MachineGun:Clone().Parent = plr.StarterGear game.plr.leaderstats.Cash.Value = game.plr.leaderstats.Cash.Value - 500 end end end)
Good luck in your game! :D
Check ifyou have FilteringEnabled turned on. If it is turned on then make a RemoteEvent in ReplicatedStorage Change your scripts to this:
local plr = game.Players.LocalPlayer local replicatedstorage = game:GetService("ReplicatedStorage") script.Parent.MouseButton1Click:connect(function() if plr.leaderstats.Cash.Value >= 500 then replicatedstorage.MachineGun:Clone().Parent = plr.Backpack replicatedstorage.MachineGun:Clone().Parent = plr.StarterGear game.ReplicatedStorage.RemoteEvent:FireServer(500) end end)
insert a script into ServerScriptService and enter the following script:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player , amount) player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 500 end)
You've already indicated if someone MouseButton1Clicks and if their money value is 500 or over so instead it would be:
local plr = game.Players.LocalPlayer local replicatedstorage = game:GetService("ReplicatedStorage") script.Parent.MouseButton1Click:connect(function() if plr.leaderstats.Cash.Value >= 500 then replicatedstorage.MachineGun:Clone().Parent = plr.Backpack replicatedstorage.MachineGun:Clone().Parent = plr.StarterGear plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value end end)
Also in the script that you made:
local plr = game.Players.LocalPlayer local replicatedstorage = game:GetService("ReplicatedStorage") script.Parent.MouseButton1Click:connect(function() if plr.leaderstats.Cash.Value >= 500 then replicatedstorage.MachineGun:Clone().Parent = plr.Backpack replicatedstorage.MachineGun:Clone().Parent = plr.StarterGear if script.Parent.MouseButton1Click and plr.leaderstats.Cash.Value >= 500 then game.plr.leaderstats.Cash.Value = ERROR IS HERE : game.plr.leaderstats.Cash.Value - 500 end end end)
Where it says "ERROR IS HERE", basically, the error is that you've already made a variable called plr, so there's no point is saying 'game.plr.leaderstats.Cash.Value - 500' when instead you can just say 'plr.leaderstats.Cash.Value - 500'
I hope this answered your question!