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

Even though a player is the same level as in the if statement, the else statement runs instead,help?

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

0

Did you make sure that the players Lvl is greater then or equal to 2?

0

Yes

0

maybe put val = 2 inside of the touched function?

0

Doesn't work

0

When I print the Lvl value it says 0, even though it says on the leaderboard it is 5

1 answer

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