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

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

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)

8 comments

1

try adding one more "end"

0

That end gets underlined red!

0

arrangement is key

0

also Walkspeed should be "WalkSpeed"

0

"connect" should be "Connect".

0

indent ur code

0

Your 3rd end needs the ) (Instead of the 4th one) and then you need an extra end after that.

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.

1 answer

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.

4 comments

0

Hope it helped!

0

another really dumb answer

0

for Christ's sake, Mouse returns the mouse not the keyboard

0

"key" can only be detected through UserInput/ContextAction service

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