Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does it say the character is nill???

This is the Local Script that is located in a folder , which is located in a tool.

"19:46:26.925 - Players.Tizzel40.Backpack.DefultCombat.Scripts.ClickFire:4: attempt to index local 'char' (a nil value)"

local tool = script.Parent.Parent

local player = game.Players.LocalPlayer

local char = player.Character

local hum = char:WaitForChild("Humanoid")

  

  

  

local mouse = player:GetMouse()

  

local uis = game:GetService("UserInputService")

local Remotes = tool:WaitForChild("Remotes")

----------TOOL SETTING

local inuse = false

local cooldown = .7

local Damage = math.random(5,10)

------------------------------

local usedright = false

  

local IdleAnimation = hum:LoadAnimation(tool:WaitForChild("Animations").IdleAnimation)

  

  

  

tool.Equipped:Connect(function()

IdleAnimation:Play()

end)

  

  

tool.Unequipped:Connect(function()

IdleAnimation:Stop()

end)

  

tool.Activated:Connect(function()

if inuse == false then

inuse = true

if usedright == false then

usedright = true

Remotes.CombatEvent:FireServer(Damage,"RightHand")

wait(cooldown)

inuse = false

else

Remotes.CombatEvent:FireServer(Damage,"LeftHand")

wait(cooldown)

inuse = true

end

end

end)

2 comments

0

for some reason the code blocks didnt work for me???

0

The Problem is , Since the character is somehow "nil" the animation wont play........, :(

1 answer

✓ Accepted answer

What happened is that the script loaded before the character so you'll have to use the CharacterAdded:Wait() event to yield for the character:

local tool = script.Parent.Parent
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

1 comment

0

oh okay thx

This discussion is preserved as it was. New answers, comments, and votes are closed.