Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Workspace.Dummy.Controller.Attack:17: attempt to index nil with 'WalkSpeed' ?

Asked by 2 years ago
Edited 2 years ago

local attackCooldown = 1 local attackWindup = 0.5 local attackRange = 3 local attackDamage = 20

local char = script.Parent.Parent local hum = char:WaitForChild("Humanoid") local originalWalkSpeed = hum.WalkSpeed

local canAttack = true

script.Parent.AttackRemote.Event:Connect(function(plrRoot)

if not canAttack then return end
canAttack = false

hun.WalkSpeed = 0.1

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://7209529782"
local playAnim = hum:LoadAnimation(anim)
playAnim:Play()

wait(attackWindup)
local newDistance = (char.HumanoidRootPart.Position - -plrRoot.Position).magnitude
if newDistance <= attackRange + 5 then 

    if plrRoot.parent.Player.isBlocking.Value == true then
        attackDamage *= 0.5
    end
    plrRoot.Parent.Humanoid:takeDamage(attackDamage)

wait(attackCooldown)
hum.WalkSpeen = orininalWalkSpeed
canAttack = true

end
end)

2 answers

Log in to vote
0
Answered by
D4_rrk 89
2 years ago

Lua is case sensitive, so you need the 's' to be also capitalized.

hun.WalkSpeed = 0.1
0
still broke OpticsOnline 6 — 2y
0
You also misspelled WalkSpeed with WalkSpeen and originalWalkSpeed with orininalWalkSpeed. It should be hum.WalkSpeed = originalWalkSpeed D4_rrk 89 — 2y
0
In the future, if you get errors make sure to re-read your code to make sure any capitals are capitalized and any misspellings are changed. D4_rrk 89 — 2y
0
yeah, i fixed all that and it still doesnt work. OpticsOnline 6 — 2y
View all comments (9 more)
0
What is the error message that you have gotten now? D4_rrk 89 — 2y
0
same error massage OpticsOnline 6 — 2y
0
just with caps OpticsOnline 6 — 2y
0
Workspace.Dummy.Controller.Attack:17: attempt to index nil with 'WalkSpeed' OpticsOnline 6 — 2y
0
Would you mind providing me with the line of code where the error appears. You can do this by clicking on the error message and it will direct you to the line of code where the error occurred. D4_rrk 89 — 2y
0
hun.WalkSpeed = 0.1 OpticsOnline 6 — 2y
0
You misspelled hum with hun. So it should be hum.WalkSpeed = 0.1 D4_rrk 89 — 2y
0
I hope this solved your issue. D4_rrk 89 — 2y
0
tysm OpticsOnline 6 — 2y
Ad
Log in to vote
0
Answered by
appxritixn 2235 Moderation Voter Community Moderator
2 years ago

Problem:

You are trying to set a value of a misspelled variable, and failed to capitalize the 'S' in hum.WalkSpeed.

Solution:

Fix the misspelled words and capitalization.

Code:

local attackCooldown = 1 
local attackWindup = 0.5 
local attackRange = 3 
local attackDamage = 20

local char = script.Parent.Parent 
local hum = char:WaitForChild("Humanoid") -- the variable you defined
local originalWalkSpeed = hum.WalkSpeed

local canAttack = true

script.Parent.AttackRemote.Event:Connect(function(plrRoot)
    if not canAttack then return end
        canAttack = false

        hum.WalkSpeed = 0.1 -- this was "hun.Walkspeed"

        local anim = Instance.new("Animation")
        anim.AnimationId = "rbxassetid://7209529782"
        local playAnim = hum:LoadAnimation(anim)
        playAnim:Play()

        wait(attackWindup)
        local newDistance = (char.HumanoidRootPart.Position -  plrRoot.Position).magnitude
        if newDistance <= attackRange + 5 then 

            if plrRoot.parent.Player.isBlocking.Value == true then
                attackDamage *= 0.5
            end
            plrRoot.Parent.Humanoid:takeDamage(attackDamage)

        wait(attackCooldown)
        hum.WalkSpeed = orininalWalkSpeed -- this was "hum.Walkspeed"
        canAttack = true

    end
end)
0
how do i spell it correctly? OpticsOnline 6 — 2y

Answer this question