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.
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
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)