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

Is there something wrong with my elseif statement?

I'm working on a skip stage for my obby but there's something wrong with my script. This is a local script.

local player = game.Players.LocalPlayer
local stage = player:WaitForChild("leaderstats"):FindFirstChild("Stage")
local skipped = player:WaitForChild("leaderstats"):FindFirstChild("StageSkipped")
local skipLimit = player:FindFirstChild("Skip")
local hasLimits = true
local originalLimit = 3


script.Parent.MouseButton1Click:Connect(function()
	if hasLimits == true then
		if originalLimit ~= 0 then
			originalLimit = originalLimit - 1
			stage.Value = stage.Value + 1
			skipped.Value = skipped.Value + 1
			if player ~= nil and player.Character ~= nil and player.Character:FindFirstChild("Humanoid").Health > 0 then
				player.Character.HumanoidRootPart.CFrame = game.Workspace.CheckPoints:FindFirstChild(stage.Value).CFrame + Vector3.new(0,3,0)
			end
		end
	elseif skipLimit.Value ~= 0 then
		skipLimit.Value = skipLimit.Value - 1
		stage.Value = stage.Value + 1
		skipped.Value = skipped.Value + 1
		if player ~= nil and player.Character ~= nil and player.Character:FindFirstChild("Humanoid").Health > 0 then
			player.Character.HumanoidRootPart.CFrame = game.Workspace.CheckPoints:FindFirstChild(stage.Value).CFrame + Vector3.new(0,3,0)
		end
	end
end)

For some reason the "elseif " statement, it doesn't work. The "SkipLimit variable at the top is linked to the player skip.Value. Example, player A is at stage 2 and he has not used the 3 skips (that is default every player will have 3 skips at the start of the game) and when I join the server, player A in the same server as me gets an extra 3 skips such that player A has a total of 6 skips. But when he uses the 3 default skips then he will only have 3 remaining skips(6-3). The script I have will always minus the 3 default skips that player A has before going to the new 3 skips. But after using the default skips, the 3 extra skips that player A has gotten from me when I joined the game, doesn't work. I have tried using print statements but nothing comes out.

Oh, and is there any other way that I can do to stop player A from killing himself to get the 3 default skips back without waiting 2 minutes? So that the player will not keep killing himself to get the 3 skips without waiting.

I know this was a long one, but I tried to fit as many information(those important ones) as I could without making a whole passage as it would be tiring to read all of it. If I did miss out any useful information, I'm sorry, I did this in a rush. Feel free to ask me questions if you still don't understand!

Thanks.

1 answer

✓ Accepted answer

Your issue is you've made a variable that never changes, and you've made it so that the elseif relies on it changing. I removed the hasLimits variable since it didnt seem to be doing anything.

local player = game.Players.LocalPlayer
local stage = player:WaitForChild("leaderstats"):FindFirstChild("Stage")
local skipped = player:WaitForChild("leaderstats"):FindFirstChild("StageSkipped")
local skipLimit = player:FindFirstChild("Skip")
local originalLimit = 3


script.Parent.MouseButton1Click:Connect(function()
    if originalLimit ~= 0 then
        originalLimit = originalLimit - 1
        stage.Value = stage.Value + 1
        skipped.Value = skipped.Value + 1
        if player ~= nil and player.Character ~= nil and player.Character:FindFirstChild("Humanoid").Health > 0 then
            player.Character.HumanoidRootPart.CFrame = game.Workspace.CheckPoints:FindFirstChild(stage.Value).CFrame + Vector3.new(0,3,0)
        end
    elseif originalLimit == 0 and skipLimit.Value ~= 0 then
        skipLimit.Value = skipLimit.Value - 1
        stage.Value = stage.Value + 1
        skipped.Value = skipped.Value + 1
        if player ~= nil and player.Character ~= nil and player.Character:FindFirstChild("Humanoid").Health > 0 then
            player.Character.HumanoidRootPart.CFrame = game.Workspace.CheckPoints:FindFirstChild(stage.Value).CFrame + Vector3.new(0,3,0)
        end
    end
end)

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