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

when the npc attacks it slows down but never speeds up again, any clue why?

Asked by 3 years ago
Edited by JesseSong 3 years ago

there are no error code, it just doesn't seem to work


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 hum.WalkSpeed = 0.1 local anim = Instance.new("Animation") anim.AnimationId = "rbxassetid://7215836748" 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 = originalWalkSpeed canAttack = true end end)
0
fixed codeblock JesseSong 3916 — 3y
0
did you use print statements? JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

I think the NCP might be breaking because you defined origin walkspeed as the humanoid's walkspeed. This means when you use originalWalkSpeed, it gets the humanoid's current walkspeed. You're basically telling the script to set the humanoid's walkspeed to itself. You can fix this by writing something similar to this:

local OriginWalk = instance.new("NumberValue", char)
OriginWalk.Value = hum.Walkspeed

You can then use this value later in the script, rather than originalWalkSpeed.

0
do i want to erase any line or just put those lines at the end? OpticsOnline 6 — 3y
0
eras local originalWalkSpeed = hum.WalkSpeed and put that script at that line WINDOWS10XPRO 438 — 3y
0
No, you replace where you define originalwalkspeed with the two lines, then erase originalwalkspeed on line 34 and replace it with OriginWalk. TheB4dComputer 100 — 3y
0
it came out with an error Workspace.Entity.Controller.Attack:8: attempt to index nil with 'new' OpticsOnline 6 — 3y
View all comments (8 more)
0
Oh, my bad. The instance's "I" should be capitalized TheB4dComputer 100 — 3y
0
that didnt fix it OpticsOnline 6 — 3y
0
hes still slow i mean, it did fix the other error tho. OpticsOnline 6 — 3y
0
Where did you write the two lines of code? If you haven't already, try putting the code where you're defining everything. TheB4dComputer 100 — 3y
0
i replaced line 8 with local OriginWalk = Instance.new("NumberValue", char) and add a line underneath for OriginWalk.Value = hum.WalkSpeed  OpticsOnline 6 — 3y
0
Okay, try this. Manually add a value in the ncp and replace "Instance.new("NumberValue", char)" with script.Parent.WhateverYouCalledTheValue TheB4dComputer 100 — 3y
0
local sprint = ? OpticsOnline 6 — 3y
0
So it's possible the code isn't speeding up because the value, as I said in the answer, is pointing to the walkspeed. You can fix this by adding a value into the humanoid manually and getting the value from the script. TheB4dComputer 100 — 3y
Ad

Answer this question