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

Why doesn't this change the players rep?

So I have this admin gui, and there's a text button and box to change a player's rep (leaderstat), but when I type in the value in the text box and press the button, it just changes the rep to 0. Here's the script.

function clicked4()
local plr = game.Players:FindFirstChild(k.Text)
local plrRep = plr.leaderstats.Reputation
	if plr ~= nil then
		plrRep.Value = r.Text else if
	plr == nil then
		o.Text = k.Text.." does not exist."
end; end; end

script.Parent.adminOpen.addRep.MouseButton1Down:connect(clicked4)


1 answer

If the rep is a NumberValue or an IntValue then be sure to convert the string to a number before changing the rep.

function clicked4()
	local plr = game.Players:FindFirstChild(k.Text)
	local plrRep = plr.leaderstats.Reputation
	if plr ~= nil and tonumber(r.Text) ~= nil then
		plrRep.Value = plrRep.Value == tonumber(r.Text)
	elseif plr == nil then
		o.Text = k.Text.." does not exist."
	elseif tonumber(r.Text) == nil then
		o.Text = k.Text.." is not a number."
	end
end

script.Parent.adminOpen.addRep.MouseButton1Down:connect(clicked4)

In other words, tonumber. tonumber returns nil when the string cannot be converted into a number, otherwise returns the number. I've also cleaned up your code a little bit, I hope you don't mind.

If you have any questions, contact me. I'll be happy to help!

1 comment

0

It doesn't work, all it does is say "Player1 is not a number".

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