Hello. I am currently making a gun shop for my game, and in order to do this I am trying to remove 4000 money in the leaderstats folder as a form of payment, this is not working.
For some reason the scrpt thinks that the amount of money is just how much they joined and had, I am changing the values manually but it thinks the value is 0
I have deleted and re wrote it multiple times, I went on to a few other projects I made with the exact same thing and copied their scripts, for some reason it is bent on not updating the value.
Here are the scripts
LOCAL SCRIPT
local plr = game:GetService("Players").LocalPlayer
local money = plr:WaitForChild("leaderstats").Money
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Title.Text == "AK74M" then
local price = 4000
if money.Value >= price then
game.ReplicatedStorage.LegalGunShop.BuyEvents.AK74M:FireServer(plr)
end
end
end)
If you take a look at the params of FireServer, a player object isn’t one of them, because when you fire to the server the player is always the first argument anyways. Remove it and try again.
I’d suggest actually verifying if the player has sufficient funds on the server, not on the client.
-- Client
local Player = game:GetService('Players').LocalPlayer
local Events = game.ReplicatedStorage:WaitForChild('LegalGunShop').BuyEvents
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Title.Text == "AK74M" then
Events.AK74M:FireServer()
end
end)
-- Server
local Events = game.ReplicatedStorage:WaitForChild('LegalGunShop').BuyEvents
local Price = 4000
Events.AK74M.OnServerEvent:Connect(function(player)
local stats = player:WaitForChild('leaderstats')
if stats.Money.Value >= Price then
stats.Money.Value -= 4000
-- Rest of your code
end
end)
local plr = game:GetService("Players").LocalPlayer
local money = plr:WaitForChild("leaderstats").Money
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Parent.Title.Text == "AK74M" then
local price = 4000
if money.Value >= price then
game.ReplicatedStorage.LegalGunShop.BuyEvents.AK74M:FireServer()
end
end
end)
alright so when you’re trying to manually put some coins or currency in studio try doing it server sided and not client sided like in this video. the server thinks you have 0 coins because you just changed the 4000 in the client. here is a gif on what i mean by changing from client to server https://gyazo.com/a913c5aff8345b17500b8b8b4872a2c2