Hi I’m trying to make a Shop Gui that decreases you’re Leaderstats Currency if you have bought an item but the script somehow bugs and decreases the wrong number:
This is the script I use:
local Player = script:FindFirstAncestorWhichIsA("Player")
local Tool = game.ReplicatedStorage.BusinessItems.JokeGun
game.ReplicatedStorage.BusinessEvent.BobGeneralStoreEvent.OnServerEvent:Connect(function()
Player.leaderstats.Rubles.Value = Player.leaderstats.Rubles.Value - 10
Tool:Clone().Parent = Player.Backpack
end)
local Tool = game.ReplicatedStorage.BusinessItems.JokeGun
game.ReplicatedStorage.BusinessEvent.BobGeneralStoreEvent.OnServerEvent:Connect(function(Player)
local Leaderstats = Player:FindFirstChild('leaderstats')
if Leaderstats and Tool then
Player.leaderstats.Rubles.Value -= 10
Tool:Clone().Parent = Player.Backpack
end
end)
Okay, I tried the old code. Both work perfectly fine. So there is obviously something else going on here.
(only thing I removed from the old code was local Player = script:FindFirstAncestorWhichIsA("Player"))
(replaced with OnServerEvent:Connect(Function(Player)
Kindly switch to server side while testing and find the path location of your NumberValue. As per your issue, I assume that the server cannot see the NumberValue. In order to fix this, change the location of NumberValue to a leaderstats folder or else into Player (as shown in below code) which then gets transferred to the Player’s folder whenever a new Player joins.
Player.PlayerAdded....(Player)
local NumberValue = Instance.new("NumberValue",Player)
--other changes for NumberValue
end)
Sorry I just now read your previous messages before mine and I see that your NumberValue is located in the leaderstats.
The Rubles does get incremented or changed from your serverside but you have to change the NumberValue of your script in the serverscriptservice itself.
local Tool = game.ReplicatedStorage.BusinessItems.JokeGun
game.ReplicatedStorage.BusinessEvent.BobGeneralStoreEvent.OnServerEvent:Connect(function(Player)
local Leaderstats = Player:FindFirstChild('leaderstats')
if Leaderstats and Tool then
local Decreased = Player.leaderstats.Rubles.Value - 10
Player.leaderstats.Rubles.Value -= 10
Player.PlayerGui...Text = tostring(Decreased)
Tool:Clone().Parent = Player.Backpack
end
end)
Was the default value of IntValue “Rubles” was 1000? or did you set it from the client?
If you did set the value of IntValue (to 1000), the value SHOULD be -10 because the change doesnt replicate to server. ( you’ve set the value of IntValue on your client, which does not replicate to serverside. )
Also If you didn’t set the value in client, and the game set your Rubles value to 1000, then you should probably check the script that sets the Ruble(IntValue)'s Value to 1000, If that is localScript, the value of Rubles doesn’t replicate to server. which means server will still know the value of Ruble as 0. so it changes the value to -10. ( 0 - 10 = -10 )
So, the problem looks like to be replicating problem, you should check your LocalScripts, and add some remoteEvents to set the value in server.
local Player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
if Player.leaderstats.Rubles.Value >= 10 then
game.ReplicatedStorage.BusinessEvent.BobGeneralStoreEvent:FireServer()
script.Parent.Parent.Parent.Parent.Parent.Parent.BobGeneralStore.Enabled = false
end
end)