Doesn't set the Value to 100 but set in script

Why doesn’t it set the value to 100,but I set it in the script to 100?!

local function leaderstats(plr)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = plr
	local kills = Instance.new("IntValue")
	kills.Name = "Kills"
	kills.Parent = stats
	local deaths = Instance.new("IntValue")
	deaths.Name = "Deaths"
	deaths.Parent = stats
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Parent = stats
	local Once = Instance.new("BoolValue")
	Once.Name = "Once"
	Once.Parent = plr
	local level = Instance.new("IntValue")
	level.Name = "Level"
	level.Parent = stats
	local XP = Instance.new("IntValue")
	XP.Name = "XP"
	XP.Parent = plr
	local XP_need = Instance.new("NumberValue")
	XP_need.Value = 100
	XP_need.Name = "XP_need"
	XP_need.Parent = plr
	XP:GetPropertyChangedSignal("Value"):Connect(function()
		if XP.Value == plr:WaitForChild("XP_need").Value then
			plr.XP_need.Value += 100
			level.Value += 1
		end
	end)
	plr.CharacterAdded:connect(function(char)
		local humanoid
		repeat
			humanoid = char:FindFirstChild("Humanoid")
			wait()
		until humanoid
		humanoid.Died:connect(function() 
			deaths.Value = deaths.Value + 1 
			local tag = humanoid:FindFirstChild("creator") 
			if tag then  
				local killer = tag.Value  
				if killer and killer ~= plr then   
					local killername = killer.Name
					killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
					killer.leaderstats.Cash.Value = killer.leaderstats.Cash.Value + 100
					killer.XP.Value = killer.XP.Value + 50
					killEvent:FireAllClients(plr,killername)
				end   
			end 
		end)     
	end)
end

I don’t really know why your value isn’t set to 100 but if you want a small tips, you don’t need to do an Xp_need value. ^^
You can directly do a calcul like this for example:

XP:GetPropertyChangedSignal("Value"):Connect(function()
	if XP.Value >= 100 * level.Value then
		level.Value += 1
	end
end)

Another example in case if your exp required isn’t linear

XP:GetPropertyChangedSignal("Value"):Connect(function()
	if level.Value >= 1 and level.Value < 5 and XP.Value >= 100 * level.Value then
		level.Value += 1
    elseif level.Value >= 5 and level.Value < 9 and XP.Value >= 250 * level.Value then
		level.Value += 1
	end
end)
1 Like

game.Players.PlayerAdded:connect(leaderstats)

for i,plr in pairs(game.Players:GetPlayers()) do
leaderstats(plr)
end

local killEvent = Instance.new(“RemoteEvent”)
killEvent.Name = “killedEvent”
killEvent.Parent = game.ReplicatedStorage

local tag = Instance.new(“StringValue”)
tag.Name = “creator”
tag.Parent = game.Workspace

local function onTouch(hit,player)
local humanoid = hit.Parent:FindFirstChild(“Humanoid”)
if humanoid then
humanoid.Health = 0
tag.Value = player
end
end

game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
char:WaitForChild(“HumanoidRootPart”).Touched:connect(function(hit)
onTouch(hit,plr)
end)
end)
end)

for i,plr in pairs(game.Players:GetPlayers()) do
if plr.Character then
local char = plr.Character
char:WaitForChild(“HumanoidRootPart”).Touched:connect(function(hit)
onTouch(hit,plr)
end)
end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.