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

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

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

✓ Accepted answer

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

hun.WalkSpeed = 0.1

13 comments

0

still broke

0

You also misspelled WalkSpeed with WalkSpeen and originalWalkSpeed with orininalWalkSpeed. It should be hum.WalkSpeed = originalWalkSpeed

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.

0

yeah, i fixed all that and it still doesnt work.

0

What is the error message that you have gotten now?

0

same error massage

0

just with caps

0

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

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.

0

hun.WalkSpeed = 0.1

0

You misspelled hum with hun. So it should be hum.WalkSpeed = 0.1

0

I hope this solved your issue.

0

tysm

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)

1 comment

0

how do i spell it correctly?

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