How To Change Player Values in a Regular Script

Hi again! I have a regular script in my game in which I would like to a part to increase a player’s value (located in the LocalPlayer). I need it to be in my regular script because the script in itself will not work if used in a local script. How should I go about doing this? The value would be in Players → LocalPlayer → leaderstats → Value

1 Like

This question is extremely vague, what exactly are you trying to change, and in what context. Is it leaderstats values? What is it? Without this info it is gonna be very difficult to help you out

I assume you want to increase a value under the player whenever they touch a part?
In that case, simply connect to its Touched from a server script, then get the player from the character that touched it, and increase the value under it:

part.Touched:Connect(function(hit)
    local char = hit:FindFirstAncestorOfClass("Model")
    if char then
        local plr = game.Players:GetPlayerFromCharacter(char)
        if plr then
            plr.SomeValueName.Value = plr.SomeValueName.Value + 1
        end
    end
end)

(of course it’s just an example, you should make sure the value exists, change its path, etc etc.)

4 Likes

yes, that’s approximately what I want to do. Its actually a part with a clickDetector that gets clicked

Yea then use the ClickDetector’s MouseClick event. It passes the player param for you, so you don’t have to worry about getting it:

part.ClickDetector.MouseClick:Connect(function(plr)
    plr.leaderstats.Something.Value = plr.leaderstats.Something.Value + 1
end)

Ah. i forgot to mention something. My clickDetector has a code to it which make it have a cooldown, which basically means that the player’s value only increases when the cooldown is over, not everytime the player clicks it.

Then you would modify the code provided by @Amiaa16 to respect your cooldown.