#attempt to index nil with 'Character'

1 messages · Page 1 of 1 (latest)

high spade
#
local dashBE = script.Parent

local lp = game:GetService("Players").localPlayer
local char = lp.Character
local hrp: Part = char:WaitForChild("HumanoidRootPart")
local hum: Humanoid = char:WaitForChild("Humanoid")
local animator: Animator = hum:WaitForChild("Animator")

local dashDuration = 0.35
local rate = 0.01

dashBE.OnInvoke = function(dashDirection)

    local bv= Instance.new("BodyVelocity")
    bv.MaxForce = Vector3.new(100000, 0, 100000)
    bv.Parent = hrp

    local dashStrength = 100

    local mds = dashDuration * 0.15

    local amountOfIterations = dashDuration / rate

    local removalOfStrengthPerIteration = dashStrength / amountOfIterations

    for i = 0, dashDuration, rate do

        if dashDirection == "Front" then

            bv.Velocity = hrp.CFrame.LookVector * dashStrength

        elseif dashDirection == "Back" then

            bv.Velocity = (hrp.CFrame.LookVector * -1) * dashStrength

        elseif dashDirection == "Right" then

            bv.Velocity = hrp.CFrame.RightVector * dashStrength

        elseif dashDirection == "Left" then

            bv.Velocity = (hrp.CFrame.RightVector * -1) * dashStrength

        end

        if dashStrength > mds then

            dashStrength -= removalOfStrengthPerIteration

            if dashStrength < mds then

                dashStrength = mds

            end

        end

        task.wait(rate)

    end

    bv:Destroy()

end
broken creekBOT
#

studio** You are now Level 3! **studio

high spade
#

It was working fine earlier now I'm getting an erro saying attempt to index nil with character

#
local uis = game:GetService("UserInputService")

local dashBE = script:WaitForChild("Dash")

uis.InputBegan:Connect(function(input, gameProcessed)
    
    if not gameProcessed then
        
        if input.KeyCode == Enum.KeyCode.Q then
            
            local dashDirection = "Front"
            
            if uis:IsKeyDown(Enum.KeyCode.A) then
                
                local dashDirection = "Left"
                
            elseif uis:IsKeyDown(Enum.KeyCode.D) then
                
                local dashDirection = "Right"
                
            elseif uis:IsKeyDown(Enum.KeyCode.W) then
                
                local dashDirection = "Back"
                
            end
            
            dashBE:Invoke(dashDirection)
            
        end
        
    end
    
end)

This is also important since it is the script parent and calls to the script

worthy comet
#

try this @high spade

#

lp.Character or lp.CharacterAdded:Wait()

#

as the character may have not loaded in yet that’s why it is nil

high spade
#

in which set of code should I add it?
The full error is Workspace.kIefkey.InputManager.Dash.Script:4: attempt to index nil with 'Character'

worthy comet
#

where do you think

high spade
#

I put it into the InputManager local script and it did nothing let me try the Dash Script

worthy comet
#

put it where ??

high spade
#

It's two different scripts one is used to detect the direction while the other is used to actually move the character based on the hrp

worthy comet
#

do u know what ur scripts even do

#

as in the syntax

high spade
#

Yes it was working before but its not working anymore

worthy comet
#

New to scripting or?

high spade
#

Kind of I have some python experience but that doesnt transfer very well

worthy comet
#

It transfers great

#

In your output it tells you which line and script the error is from

#

You don’t just copy and paste the line I sent anywhere in your script with no purpose 😂

#

Add it to where you define the character variable

high spade
#

Its telling me Source not available

#

I did though

worthy comet
#

Elaborate?

#

Show the error?

#

The new code?

high spade
#
local dashBE = script.Parent

local lp = game:GetService("Players").localPlayer
local char = lp.CharacterAdded:Wait()
local hrp: Part = char:WaitForChild("HumanoidRootPart")
local hum: Humanoid = char:WaitForChild("Humanoid")
local animator: Animator = hum:WaitForChild("Animator")

local dashDuration = 0.35
local rate = 0.01

dashBE.OnInvoke = function(dashDirection)

    local bv= Instance.new("BodyVelocity")
    bv.MaxForce = Vector3.new(100000, 0, 100000)
    bv.Parent = hrp

    local dashStrength = 100

    local mds = dashDuration * 0.15

    local amountOfIterations = dashDuration / rate

    local removalOfStrengthPerIteration = dashStrength / amountOfIterations

    for i = 0, dashDuration, rate do

        if dashDirection == "Front" then

            bv.Velocity = hrp.CFrame.LookVector * dashStrength

        elseif dashDirection == "Back" then

            bv.Velocity = (hrp.CFrame.LookVector * -1) * dashStrength

        elseif dashDirection == "Right" then

            bv.Velocity = hrp.CFrame.RightVector * dashStrength

        elseif dashDirection == "Left" then

            bv.Velocity = (hrp.CFrame.RightVector * -1) * dashStrength

        end

        if dashStrength > mds then

            dashStrength -= removalOfStrengthPerIteration

            if dashStrength < mds then

                dashStrength = mds

            end

        end

        task.wait(rate)

    end

    bv:Destroy()

end
worthy comet
#

so show output

high spade
worthy comet
#

i said

#

lp.Character or lp.CharacterAdded:Wait()

#

ok wait

#

is it a local script

high spade
#

No

worthy comet
#

Your trying to get the local player in a server script

high spade
#

I don't get what you mean

worthy comet
#

client server model??

#

are you familiar

high spade
#

no

worthy comet
#

well that’s literally the core of roblox scripting

#

so i advise learn that before trying to make these systems

#

localplayer is only accessible in a local script

#

where did u get this code from

high spade
#

I made it myself and as I said it was working I don't know why it stopped

worthy comet
#

make it a local script

high spade
#

Fixed the error but now the dash isnt working

worthy comet
#

where is this code just wondering

#

is it in workspace

high spade
#

StarterCharacterScripts

#

Im going to try something give me a sec

#

Got it

broken creekBOT
#

studio** You are now Level 4! **studio

worthy comet
#

ok

#

so normal scripts can’t run in startercharacterscript properly

queen hedge
#

Idk who told you that

#

But they can't script for shit.

#

All the scripts from StarterCharacterScripts are trasnferred to the players character on spawn. If server scripts couldnt function properly when parented to the character then Roblox's health script wouldn't exist.

queen hedge
high spade
#

I already gott it to work