What The Problem Is:
So when changing leader-stat values I only know how to script it for the client, but that does not change the values correctly so how would I be able to do it using the server?
How It Doesn’t Work:
When using the client for changing values it doesn’t change it fully as in if you had a currency increase script and you changed the value, when your currency increased it would increase from the amount you had before you changed the value.
Finding Answers:
I have tried looking it up on the web, but I couldn’t find any solutions, I also tried to Fire a remote event, but how would you put this together if you could? (Not asking for a full script just an example).
I hope I do find an answer to this because it is very crucial to my game, please tell me anything you know on this, thanks.
1 Like
thanks I will look into this.
yes definitely that would be embarrassing
A complete server-sided script without duplicates, also eliminates value objects:
local Players = game:GetService("Players")
local playerStats = {}
local function getDefaultStats()
return {
Cash = 0;
Experience = 0;
}
end
Players.PlayerAdded:Connect(function(player)
playerStats[player.UserId] = getDefaultStats()
-- optional
while player.Parent do
wait(5)
if playerStats[player.UserId] then -- oops
playerStats[player.UserId]["Cash"] = playerStats[player.UserId]["Cash"] + 100
end
end
end)
Players.PlayerRemoving:Connect(function(player)
playerStats[player.UserId] = nil
end)
In order to change it from server, you will have to find the player’s UserId and change the values in the scope of the script.
thanks guys it worked really appreciate it.
Happy Developing!
I also edited @MarineMike826 script so it only does it once and his script was easier to understand I appreciate it.
I plan on adding the FireServer function to this as well please note.
Example For New Viewers
local playerModel = script.Parent
local player = game.Players:GetPlayerFromCharacter(playerModel)
player:WaitForChild("leaderstats")
player.leaderstats:WaitForChild("Cash")
local cash = player.leaderstats.Cash
if cash.Value>=10 then
cash.Value = cash.Value - 10
end
2 Likes
yeah if I did it the loop way it would just be a big mess thanks