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?
The character needs to load try:
character = player.CharacterAdded:wait()
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