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

Why cant I define character with local script!?

Asked by 6 years ago

I have defined characters with local scripts before, but now for some reason it never works. It says character is a nil value. Please help me and thanks. Here is my scripts.

local player = game.Players.LocalPlayer
local character = player.Character
local toolclone = workspace.ClassicSword:Clone()

function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
            game:GetService("Chat"):Chat(player.Character.Head, "Ninja!","Black")
            character.Humanoid:EquipTool(toolclone)
        end
    end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.R)

why cant I define character in this script?

0
on the first line, put this: repeat wait() until game:GetDescendants() greatneil80 2647 — 6y

2 answers

Log in to vote
0
Answered by
522049 152
6 years ago

The character needs to load try:

character = player.CharacterAdded:wait()
0
oh ok thx turbomegapower12345 48 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

or this:

repeat wait() until game.Players.LocalPlayer
repeat wait() until game.Players.LocalPlayer.Character:IsDescendantOf(workspace) -- waits till the player's character is in workspace

local player = game.Players.LocalPlayer
local character = player.Character

Answer this question