Better way to store specific player data?

As of now, I have been storing player values like hunger and thirst and stamina inside the player in an int value is there a better way to store these values so the client also has access to them.

Screenshot_1

2 Likes

All my character values I store in the character just the way you do, Is there a specific reason as to why you feel like you need to try a different method? Are there security risks involved?

Currently, it is ok way to do so however getting the character all the time can be an issue due to the player respawning and then having to reset your player.Character variable if you have one.

I’d actually store these values inside the Player themself, then you can easily do LocalPlayer.Values.x
You will need to remember to update these on CharacterAdded, here’s an example of a Script which handles that:

local players = game:GetService("Players")
local new = Instance.new

players.PlayerAdded:Connect(function(plr)
    local values = new("Folder")
    values.Name = "Values"
    values.Parent = plr
    --setup your ValueBases

    plr.CharacterAdded:Connect(function(char)
        --reset the values
        char:WaitForChild("Humanoid").Died:Connect(function()
            --alive is now false
        end)
    end)
end)
2 Likes

I just always felt like i was doing it wrong but thank you for replying.

You technically would be able to do this via tables. For stamina, you can do the decreasing on the client while you actually decrease the value on the server. It’s complicated how it works but it’s to create a visual effect where your bar is synchronised. Sometimes, people fire remote events or remote functions to keep the client and server in contact with some delay of course. In any case, it’s good to know how to actually do this with tables as in terms of being resource friendly tables are the way to go.

1 Like