Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to fix if statement triggering else even though statement applies to player?

Asked by 2 years ago

I am making a game about harvesting rocks and how you need a certain level to collect the rocks. However, one of the rocks work when I do a if statement about how much value of lvl you need but for one I put >= 1 and for one I put >= 0. When I click on the rock that isn't working it just shows the message I made that says "Insufficent level" even though my lvl is 1 so it should work prefectly. To show you heres the working script:

local rock = script.Parent
local rockhp = 3
local c = script.Parent.ClickDetector

c.MouseClick:Connect(function(player)
    local level = player.leaderstats.Level
    local rocks = player.leaderstats.Rocks
    if level.Value >= 0 then
        rock.Color = Color3.new(0.666667, 0, 0)
        rockhp = rockhp - 1
        rocks.Value += 2
        c.MaxActivationDistance = 0
    else
        script.Parent.SurfaceGui.TextLabel.Visible = true
        wait(1)
        script.Parent.SurfaceGui.TextLabel.Visible = false
    end
    if rockhp <= 0 then
        rock.Transparency = 1
        rock.CanCollide = false
        wait(10)
        rock.Transparency = 0
        rock.CanCollide = true
        rockhp = 10
    end
    wait(2)
    rock.Color = Color3.new(99, 95, 98)
    c.MaxActivationDistance = 30
end)

and then heres the one that dosen't work:

local rock = script.Parent
local rockhp = 5
local c = script.Parent.ClickDetector

c.MouseClick:Connect(function(player)
    local level = player.leaderstats.Level
    local rocks = player.leaderstats.Rocks
    if level.Value >= 1 then
        rock.Color = Color3.new(0.666667, 0, 0)
        rockhp = rockhp - 1
        rocks.Value += 6
        c.MaxActivationDistance = 0
    else
        script.Parent.SurfaceGui.TextLabel.Visible = true
        wait(1)
        script.Parent.SurfaceGui.TextLabel.Visible = false
    end
    if rockhp <= 0 then
        rock.Transparency = 1
        rock.CanCollide = false
        wait(10)
        rock.Transparency = 0
        rock.CanCollide = true
        rockhp = 10
    end
    wait(2)
    rock.Color = Color3.new(163, 162, 165)
    c.MaxActivationDistance = 30
end)

So I hope someone can answer this questions. Thanks

0
Are you leveling up your player from the client, or the server? collin1212121 146 — 2y

1 answer

Log in to vote
0
Answered by
extrorobo 104
2 years ago

I think I know why. when you said " However, one of the rocks works when I do an if the statement about how much value of lvl you need but for one I put >= 1 and for one I put >= 0." its probably because one of your rocks has only >=0 when your level is one.

I hope this helped!! please accept this answer, it would help a lot. if you have any more questions, you can contact me via Roblox my giving me a friend request

Ad

Answer this question