I am making an if statement, but else runs even though someone is 2nd level or higher.
Item = script.Parent:FindFirstChildOfClass("Tool"):Clone()
val = 2
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local char = hit.Parent
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum then
if plr:WaitForChild("leaderstats").Lvl.Value >= val then-- this doesn't run, but it should
local tool = char:FindFirstChildOfClass("Tool")
if tool then
tool:Remove()
Item.Name = "Sword"
Item.Parent = plr.Backpack
else
Item.Parent = plr.Backpack
end
else--This runs, when it shouldn't
plr.PlayerGui.ScreenGui.TextLabel.Visible = true
plr.PlayerGui.ScreenGui.TextLabel.TextColor3 = Color3.new(170,0,0)
plr.PlayerGui.ScreenGui.TextLabel.Text = "ERROR!"
wait(1)
plr.PlayerGui.ScreenGui.TextLabel.TextColor3 = Color3.new(0,0,0)
plr.PlayerGui.ScreenGui.TextLabel.Text = "You don't have enough XP!"
wait(2)
plr.PlayerGui.ScreenGui.TextLabel.Visible = false
end
end
end)

5 comments
Did you make sure that the players Lvl is greater then or equal to 2?
Yes
maybe put val = 2 inside of the touched function?
Doesn't work
When I print the Lvl value it says 0, even though it says on the leaderboard it is 5