Else if not working

I want to make a power up gui if you have a certant amount of streaks kills.

The else if is not working. But the if is.

local script:

local button = script.Parent

local frame = script.Parent.Parent

local perk1 = frame:WaitForChild(‘P1’)
local perk2 = frame:WaitForChild(‘P2’)
local perk3 = frame:WaitForChild(‘P3’)

local streak1 = false
local streak2 = false
local streak3 = false

local player = game.Players.LocalPlayer
local streak = player:WaitForChild(‘Streak’)

local ReplicatedStorage = game:GetService(‘ReplicatedStorage’)
local streaksEvent = ReplicatedStorage:WaitForChild(‘StreaksEvent’)

streak.Changed:Connect(function()
if streak.Value == 3 then
perk1.BackgroundColor3 = Color3.new(0, 255, 0)
streak1 = true
elseif streak.Value == 5 then
perk2.BackgroundColor3 = Color3.new(0, 255, 0)
streak2 = true
elseif streak.Value == 7 then
perk3.BackgroundColor3 = Color3.new(0, 255, 0)
streak3 = true
end
end)

local function perk()
if button.Activated and streak1 then
perk1.BackgroundColor3 = Color3.new(255, 0, 0)
streaksEvent:FireServer(‘perk1’, streak1)
wait(15)
streak1 = false
streaksEvent:FireServer(‘perk1’, streak1)

	--problem starts here
	
elseif button.Activated and streak2 then
	perk2.BackgroundColor3 = Color3.new(255, 0, 0)
	streaksEvent:FireServer('perk2', streak2)
	wait(15)
	streak2 = false
	streaksEvent:FireServer('perk2', streak2)
	
elseif button.Activated and streak3 then
	perk3.BackgroundColor3 = Color3.new(255, 0, 0)
	streaksEvent:FireServer('perk3', streak3)
	wait(15)
	streak3 = false
	streaksEvent:FireServer('perk3', streak3)
end

end

button.MouseButton1Down:Connect(perk)

2 Likes

If you need more info just ask.

Why is nobody answering. Please help me.
Edit: sorry if I am being rude.

elseif button.Activated and streak2 then
	perk2.BackgroundColor3 = Color3.new(255, 0, 0)
	streaksEvent:FireServer('perk2', streak2)
	wait(15)
	streak2 = false
	streaksEvent:FireServer('perk2', streak2)
	
elseif button.Activated and streak3 then
	perk3.BackgroundColor3 = Color3.new(255, 0, 0)
	streaksEvent:FireServer('perk3', streak3)
	wait(15)
	streak3 = false
	streaksEvent:FireServer('perk3', streak3)
else
   -- try adding this to see what the values are, if one of them is false then the 
   -- elseif statments won't run

   print(button.Activated, streak3, streak2)
end

The error is that when the you get the kills you can’t press the gui.

It does not work because I can’t press the gui.

Wait it might be because I did not put the script in the right button.

1 Like
Nothing to see here, solved below
-- revamped the script (kinda)

local button = script.Parent
local frame = script.Parent.Parent

local perk1 = frame:WaitForChild('P1')
local perk2 = frame:WaitForChild('P2')
local perk3 = frame:WaitForChild('P3')

local streak1 = false
local streak2 = false
local streak3 = false

local player = game.Players.LocalPlayer
local streak = player:WaitForChild('Streak')

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local streaksEvent = ReplicatedStorage:WaitForChild('StreaksEvent')

streak.Changed:Connect(function()
if streak.Value == 3 then
perk1.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
streak1 = true

-- disable the other ones because when it runs they're still active and the script is only reading them
streak2 = false
streak3 = false

elseif streak.Value == 5 then
perk2.BackgroundColor3 = Color3.fromRGB(0, 255, 0)

streak2 = true
streak1 = false
elseif streak.Value == 7 then
perk3.BackgroundColor3 = Color3.fromRBG(0, 255, 0)

streak3 = true
streak2 = false
end
end)

local function perk()
-- GuiButton.Activated is a Signal, not a boolean value

if streak1 then
perk1.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
streaksEvent:FireServer('perk1', streak1)
wait(15)
if streak1 then streak1 = false end -- check if it's enabled first
streaksEvent:FireServer('perk1', streak1)
	
elseif streak2 then
	perk2.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
	streaksEvent:FireServer('perk2', streak2)
	wait(15)
	if streak2 then streak2 = false end
	streaksEvent:FireServer('perk2', streak2)
	
elseif streak3 then
	perk3.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
	streaksEvent:FireServer('perk3', streak3)
	wait(15)
	if streak3 then streak3 = false end
	streaksEvent:FireServer('perk3', streak3)
else
   -- do stuff here, they may have a higher streak or something. (if possible)
end
end

button.MouseButton1Down:Connect(perk)
-- forgive me for no indentions but i'm tired right now :pensive:

I am so dumb it was because I put it in the wrong button.

1 Like

This can definitely be an issue! However, I also noticed that you try to access the Activated event as a property. I think if you change the

if button.Activated and streak1 then

to

if streak1 then

Seeing as you don’t fire the function until they click the button anyway, it would be redundant to check if they are currently holding it. What you are doing currently is just checking to see if the event exists (which should always return true on a button.)

1 Like