Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to change a string value on leaderstats?

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

✓ Accepted answer
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

4 comments

0

After i did, it said "leaderstat is not a valid member of MeshPart"

0

Woops, just realised what this was.

0

I fixed it

0

Thanks it works :D

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)

4 comments

0

After i did, it said "leaderstat is not a valid member of MeshPart"

0

I just made a new edit to my answer which solves that problem

0

U forgot .Value too

0

Thanks this helped :D

This discussion is preserved as it was. New answers, comments, and votes are closed.