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

Can someone answer my question on why the ends are never working!?

Asked by 5 years ago
local Player = game:GetService('Players').LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')
local Mouse = Player:GetMouse()
local Power = game.Players.LocalPlayer.leaderstats.Power
while true do
if Power.Value == "Super Speed" then
    Mouse.KeyDown:connect(function(key)
        if (key == "c") then
            if Humanoid.Walkspeed == 50 then 
                Humanoid.WalkSpeed = 10
            elseif Humanoid.WalkSpeed == 10 then
                    Humanoid.WalkSpeed = 50


            end
            end
            end
    end)

1
try adding one more "end" blazar04 281 — 5y
0
That end gets underlined red! tightanfall 110 — 5y
0
arrangement is key TheluaBanana 946 — 5y
0
also Walkspeed should be "WalkSpeed" TheluaBanana 946 — 5y
View all comments (4 more)
0
"connect" should be "Connect". XviperIink 428 — 5y
0
indent ur code User#23365 30 — 5y
0
Your 3rd end needs the ) (Instead of the 4th one) and then you need an extra end after that. RubenKan 3615 — 5y
0
Xviperlink I've litterally never had that issue, I used to always to :connect and it worked just fine, but I don't know, I don't really do it anymore. Knineteen19 307 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Okay, I think you're a little confused about how the ends work. When you have an elseif statement along with an if statement, it only requires one end, not one for every if.

Here's how you would arrange the ends:

local Player = game:GetService('Players').LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')
local Mouse = Player:GetMouse()
local Power = game.Players.LocalPlayer.leaderstats.Power
while true do
if Power.Value == "Super Speed" then
    Mouse.KeyDown:Connect(function(key)
        if key == "c" then -- You also don't need the parenthesis here.
            if Humanoid.Walkspeed == 50 then
                Humanoid.WalkSpeed = 10
            elseif Humanoid.WalkSpeed == 10 then
                Humanoid.WalkSpeed = 50
            end -- Ends off the inner-most if statement.
        end -- Ends the "if key == "c""
    end) -- Ends the KeyDown event.
end -- Ends the original if statement.

I think for the most part, you're just overcomplicating it, but that's okay, as long as you learn in the end.

0
Hope it helped! Knineteen19 307 — 5y
0
another really dumb answer DeceptiveCaster 3761 — 5y
0
for Christ's sake, Mouse returns the mouse not the keyboard DeceptiveCaster 3761 — 5y
0
"key" can only be detected through UserInput/ContextAction service DeceptiveCaster 3761 — 5y
Ad

Answer this question