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

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

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

1 comment

0

Are you leveling up your player from the client, or the server?

1 answer

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

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