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

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

Asked by 5 years ago

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)
0
Note: Always indent your code. It makes it easier to read and debug. User#21908 42 — 5y

2 answers

Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

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 :)

Ad
Log in to vote
0
Answered by 5 years ago

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.

0
KeyDown is decrepit? OBenjOne 190 — 5y
0
Yes and for a good reason. Very inconsistent and doesn't respect the game processed event. User#19524 175 — 5y
0
Yes and for a good reason. Very inconsistent and doesn't respect the game processed event. User#19524 175 — 5y

Answer this question