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

wont level up? (line8 is error) Your title should be specific! Describe your

game.Players.PlayerAdded:Connect(function(plr)
	plr:WaitForChild("stats")
	plr:WaitForChild("leaderstats")
	plr.stats:WaitForChild("exp")
	plr.leaderstats:WaitForChild("level")
	local l = plr.leaderstats.level
	local e = plr.stats.exp
	while true do
	if e.Value >= 50 then
			l.Value = l.Value +1
			wait(1)
		end
		end
end)

it wont make me level up when correct exp reached help?

1 comment

0

You're not getting the player correctly

1 answer

Here is the fix for what you want using a text button:

-- Normal script:

script.Parent.LevelUp.OnServerEvent:Connect(function() -- Im using a remote even btw
	local plr = script.Parent.Parent.Parent
	if plr.exp.Value >= 50  then
		plr.leaderstats.Level.Value = plr.leaderstats.Level.Value + 1
        plr.exp.Value = plr.exp.Value - 50
	elseif plr.exp.Value < 50  then
		-- do nothing
	end
end)

-- Local script to fire upon clicking:

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Parent.LevelUp:FireServer()
end)

The problem with your script is

1: you're not getting the player correctly.

2: "stats" is a reserved word, meaning the server thinks it's something else.

my suggestions:

1: get the player through "script.parent" method

2: make the exp's parent the player not a folder.

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