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

Hi, I've got an error in my script but I have no idea how to fix it. Help?

So I have a LocalScript in the starter pack. And its child is a sound, named sound. In Roblox Studio, line 6 gets underlined in blue. I have no idea what's wrong with it. Help?

local k = game.Players.LocalPlayer.Name
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
if key:byte() == 32 and
game.Workspace[k].Humanoid.JumpPower == 125 then
script.Sound:Play()
game.Workspace[k].Humanoid.JumpPower = 0
script.Disabled = true
end
end)

1 comment

0

Note: Always indent your code. It makes it easier to read and debug.

2 answers

✓ Accepted answer

There isn't any problem that would affect your script. It's just a warning to make cleaner code, saying that if you are going to span an if statement across multiple lines, indent the lines for better readability.

-- gives warning
if key:byte() == 32 and
game.Workspace[k].Humanoid.JumpPower == 125 then

-- does not give warning
if key:byte() == 32 and
	game.Workspace[k].Humanoid.JumpPower == 125 then

Hope this helps :)

###You should not use KeyDown to detect user input. It is very inconsistent and deprecated. Switch to UserInputService. connect is also deprecated. Also, your script will error if a player named Part joins the game LOL.

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(key, chatting)
       if chatting then return end
        
	if key.KeyCode == Enum.KeyCode.F and char.Humanoid.JumpPower == 125 then
	    script.Sound:Play()
	    char.Humanoid.JumpPower = 0
	    script.Disabled = true
	end
end)

###I don't know the byte for 32.

3 comments

0

KeyDown is decrepit?

0

Yes and for a good reason. Very inconsistent and doesn't respect the game processed event.

0

Yes and for a good reason. Very inconsistent and doesn't respect the game processed event.

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