Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to change a string value on leaderstats?

Asked by 4 years ago
script.Parent.Touched:Connect(function(plr)
    if plr.Parent:FindFirstChild("Humanoid") then
        plr.leaderstats.Area = "Noob"
    end
end)

What I wanted to do is whenever you touch a block, it changes the value of "Area" on the leaderstats to the name of that area. I've tried many different things but it doesn't seem to work.

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
script.Parent.Touched:Connect(function(obj)
    local plr = game.Players:GetPlayerFromCharacter(obj.Parent)
    if plr then
        plr.leaderstats.Area.Value = "Noob"
    end
end)

You forgot to put ".Value" after plr.leaderstats.Area

0
After i did, it said "leaderstat is not a valid member of MeshPart" Drimpetuous 6 — 4y
0
Woops, just realised what this was. firestarroblox123 440 — 4y
0
I fixed it firestarroblox123 440 — 4y
0
Thanks it works :D Drimpetuous 6 — 4y
Ad
Log in to vote
0
Answered by
ScuffedAI 435 Moderation Voter
4 years ago
Edited 4 years ago

The reason to why you're unable to change the value, is because you forgot to add .Value at line 3.

-- instead of 
plr.leaderstats.Area = "Noob"

-- change it to
plr.leaderstats.Area.Value = "Noob"

It's as simple as that

EDIT: To fix the error 'leaderstat is not a valid member of MeshPart' you have to set the leaderstats values through player and not the character. This is something that i completely forgot about.

script.Parent.Touched:Connect(function(plr)
    -- this line retrieves the player from the character
    local player = game.Players:GetPlayerFromCharacter(plr.Parent)

    if plr.Parent:FindFirstChild("Humanoid") then
        -- we change "plr" to our new "player" variable instead
        player.leaderstats.Area = "Noob"
    end
end)
0
After i did, it said "leaderstat is not a valid member of MeshPart" Drimpetuous 6 — 4y
0
I just made a new edit to my answer which solves that problem ScuffedAI 435 — 4y
0
U forgot .Value too Kriscross102 118 — 4y
0
Thanks this helped :D Drimpetuous 6 — 4y

Answer this question