For whatever reason, the “if transformed == false” keeps happening instead of the elseif even when transformed is true and not false… I’m having the same problem with the cooldown. I’ve researched it and tried changing a bunch of stuff, but nothing worked… How can I fix it? Here’s the code:
transformation = script.Parent.Equipped:Connect(function()
local serverPlayer = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
game.ReplicatedStorage.Input.OnServerEvent:Connect(function(player, input2)
if player == serverPlayer then
if input2 == Enum.KeyCode.V then
if cooldown1 == false then
cooldown1 = true
if transformed == false then
transformed = true
wait(3)
cooldown1 = false
elseif transformed == true then
transformed = false
end
end
end
end
end)
end)
I would recommend inverting your if-statemenrs to reduce nesting. What I mean is:
if a then
if b then
if c then
print("All true")
end
end
end
To:
if not a then return end
if not b then return end
if not c then return end
print("All true")
For your code I would do:
transformation = script.Parent.Equipped:Connect(function()
local serverPlayer = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
game.ReplicatedStorage.Input.OnServerEvent:Connect(function(player, input2)
if player ~= serverPlayer then return end
if input2 ~= Enum.KeyCode.V then return end
if cooldown1 then return end
cooldown1 = true
if not transformed then
transformed = true
wait(3)
cooldown1 = false
else
transformed = false
end
end)
end)
This will not solve your issue, however it will make it clearer to understand what is wrong and solve it
About your code this time: What is the purpose of having both cooldown1 and transformed? What does transformed indicate? What does cooldown1 indicate?