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

Trying to make a script where head color changes when jumping [ERROR]?

Asked by 4 years ago
Edited 4 years ago
repeat wait() until game.Players.LocalPlayer.Character

local UIS = game:GetService("UserInputService")
local jumped = false
local player = game.Players.LocalPlayer
local char = player.Character

UIS.InputBegan:connect(function(input)
    if input.Keycode == Enum.KeyCode.Space and not jumped then
        jumped = true
        local ogColor = char:FindFirstChild("Head").BrickColor
        char:FindFirstChild("Head").BrickColor = BrickColor.new("Bright blue")
        wait(0.5)
        char:FindFirstChild("Head").BrickColor = BrickColor.new(ogColor)
        jumped = false
    end
end)

As well as not being sure if this script works, I also get a "attempt to index nil with 'Character'" error in console.

I also would rather have the color change back to the original Player's head color after the jumping animation ends (rather than 0.5 seconds) but am not sure how to implement that.

1 answer

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

Hello, In your script you wrote "char = player.Character" which is not a thing, at least not anymore. The player which is in game.Players is basically the client. If you want to get the actual head it would be in the workspace, the player's physical character, which is the head, torso, shirt, hat, etc.

repeat wait() until game.Workspace:FindFirstChild(game.Players.LocalPlayer.Name) -- this would work

local UIS = game:GetService("UserInputService")
local jumped = false
local player = game.Players.LocalPlayer
local char = game.Workspace[player.Name] -- This would work as it finds the model inside workspace by getting the players name

UIS.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.Space and not jumped then -- KeyCode must be capital
        jumped = true
        local ogColor = char:FindFirstChild("Head").BrickColor
        char:FindFirstChild("Head").BrickColor = BrickColor.new("Bright blue")
        wait(0.5)
        char:FindFirstChild("Head").BrickColor = BrickColor.new(ogColor)
        jumped = false
    end
end)
0
I still get a Players.offgrey.Backpack.Script:1: attempt to index nil with 'Character' error, what could this be caused by? offgrey 0 — 4y
0
Hello, I tried out the script and got no error, did you copy it? Another thing is, your "ogColor" does nothing since it would just be bright blue. Making a variable is exactly like writing out something, and since writing out "char:FindFirstChild("Head").BrickColor" would give back bright blue, it does nothing iiConstable_Subwayx 130 — 4y
0
Oh, Im sorry, you said you got an error with backpack.script? This needs to be a local script, if you want other people to see it you need a remote event but otherwise this NEEDS to be a remote event iiConstable_Subwayx 130 — 4y
0
Yeah, I made it a Local Script, I would like other users to see it as well, it seems that it still hasn't changed the Head Color to Blue, although the error's gone away, and I thought making the ogColor variable would save the color to where I could set their head back to the normal color from blue after 0.5 seconds. offgrey 0 — 4y
Ad

Answer this question