Unnecessary errors

-- by IConsumeCheddar
local Debris = game:GetService('Debris')
local UIS = game:GetService('UserInputService')
local Player = game:GetService('Players').LocalPlayer
repeat wait() until Player.CharacterAdded
local Character = Player.Character
if workspace.AncestryChanged and workspace:FindFirstChild(Player.Name) then
else
	task.wait()	
end
local RepStorage = game.ReplicatedStorage

-- Settings
local DashTime = 0.2
local Amount = 50

local MaxForce = Vector3.new(math.huge,math.huge,math.huge)
local P = 1250

local Cooldown = false
local CooldownTime = .5

local TrailEnabled = true -- CLIENTSIDED


-- Animation

local Humanoid = Character.Humanoid
local dashAnim = Humanoid.Animator:LoadAnimation(RepStorage.Animations.DashAnim)

-- Code

this is my code but can someone tell me why i get this error? the time it worked was before i updated my dash animation. but testing it after publishing the animation got me this.

attempt to index nil with 'Humanoid

ive tried to make sure the parent is workspace, make character load and tried to put the animation part above the code part to avoid error but nothing changes

Everyone, ive found a solution. using waitforchild for humanoid and character. but if u guys would be so kind, can u tell me why this happens? I want a reason as to why this happens so i can easily fixed it in the future

I think it’s trying to get the Humanoid before the character actually loads, so it errors

Instead of using :WaitForChild(), you can change the Character variable to local Character=player.Character or player.CharacterAdded:Wait()

This means that the character will be the player’s character if there is one or it will wait for the CharacterAdded event and the event will return the character

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.