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

Why is there an orange line underneath part of my script?

So...there is an orange line underneath "rankz", "xpz", and "xpn" on lines 45-47 and i cant fix it. I need this script for leveling up but when i gain enough xp to level up it doesnt work. The minimum amount of xp needed to gain a level is 700 and in this case i replaced "Level" with "Rank"

local rank = game:GetService("DataStoreService"):GetDataStore("Ranks")
local xp = game:GetService("DataStoreService"):GetDataStore("XP")
local axp = game:GetService("DataStoreService"):GetDataStore("AXP") --Stands for amount of XP needed to level up

function savedata(dataname, playerid, value)
	game:GetService("DataStoreService"):GetDataStore(dataname):SetAsync(playerid, value)
end

game.Players.PlayerAdded:Connect(function(player)
	local leader = Instance.new("Folder")
	leader.Name = "leaderstats"
	leader.Parent = player
	local rankz = Instance.new("IntValue")
	rankz.Value = rank:GetAsync(tostring(player.userId)) or 1
	rankz.Name = "Rank"
	rankz.Parent = player:WaitForChild("leaderstats")
	local xpz = Instance.new("NumberValue")
	xpz.Value = xp:GetAsync(tostring(player.userId))
	xpz.Name = "XP"
	xpz.Parent = player
	local xpn = Instance.new("IntValue")
	xpn.Value = axp:GetAsync(tostring(player.userId)) or 700
	xpn.Name = "XpNeeded"
	xpn.Parent = player
	
	xpz.Changed:connect(function()
		if player:WaitForChild("XP").Value >=  player:WaitForChild("XpNeeded").Value then
			rankz.Value = rankz.Value+1
			xpn.Value= xpn.Value+700
			savedata("Ranks",player.userId,rankz.Value)
			savedata("XP",player.userId,xpz.Value)
			savedata("AXP",player.userId,xpn.Value)
		else
			savedata("Ranks",player.userId,rankz.Value)
			savedata("XP",player.userId,xpz.Value)
			savedata("AXP",player.userId,xpn.Value)
		end
			savedata("Ranks",player.userId,rankz.Value)
			savedata("XP",player.userId,xpz.Value)
			savedata("AXP",player.userId,xpn.Value)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
		savedata("Ranks",player.userId,rankz.Value)
		savedata("XP",player.userId,xpz.Value)
		savedata("AXP",player.userId,xpn.Value)
end)

2 comments

0

Why do you have the asterisks on lines 45-47?

0

those are the elements with the orange line underneath it. when i save it an orange line appears

1 answer

It's because the variables that you request on lines 45-47 are nil, as the variables are in a completely different function.

A different alternative for lines 45-47 would be:

savedata("Ranks", player.userId, player.leaderstats.Rank.Value)
savedata("XP", player.userId, player.XP.Value)
savedata("AXP", player.userId, player.XpNeeded.Value)

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