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?

1 comment
on the first line, put this: repeat wait() until game:GetDescendants()