Hello, im trying to make a stun so the opponent cant attack while being stunned by the enemy, i made an animation for the hit and for some reason it doesnt play. Here is the code.
local stun = script.Parent.stun
--7899158637
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7899169009"
local humanoid = script.Parent.Humanoid
local animationtrack = humanoid:LoadAnimation(animation)
stun.Changed:Connect(function()
if stun == true then
animationtrack:Play()
script.Parent.Humanoid.WalkSpeed = 0
wait(1)
elseif stun == false then
script.Parent.Humanoid.WalkSpeed = 16
end
end)
I’ve tried stun.Value.Changed too, but that didnt seem to work. Also, the script is inside a dummy since i dont have anyone to try on.
Did you ever change the value of stun? If not, then that could be a reason why it’s not working.
Another thing you could try is using “GetPropertyChangedSignal” on the value property of stun. It basically works the same way as .Changed, but it’s a little more accurate.
If these don’t work, sending your code where you change the stun value would be helpful. Thanks.
well when the stun is active itll make them imobile so false = not stunned true = stunned
also it isnt a big animation
cccomnbat script is in the tool and the npc script is inside the npc and the player
Alright. Make sure the dummy is not anchored because I don’t think animations play on anchored characters. If you need to, just set up a local server with 2 players in it, and test it that way.
Also, your pathways for your scripts don’t really make sense considering that NPCs don’t have a player object. I would instead parent the “stun” value to characters and not players.
local stun = script.Parent:WaitForChild("stun")
--7899158637
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://7899169009"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationtrack = animator:LoadAnimation(animation)
stun.Changed:Connect(function()
if stun then
animationtrack:Play()
humanoid.WalkSpeed = 0
task.wait(5)
stun.Value = false
humanoid.WalkSpeed = 16
elseif not stun then
humanoid.WalkSpeed = 16
end
end)
It doesnt work, it must be the stun.Value = true/false in the combat script.
Edit: I observed the stun value on the npc and it seems to actually change, im really confused.