I created a stun system for my boss fight game but whenever you are stunned, for some reason, you can still attack.
Server script:
wait(10)
local stompanim = Instance.new("Animation")
stompanim.AnimationId = "https://www.roblox.com/asset/?id=15474208685"
local stompdebounce = 5
local stompwait = false
local stunanim = Instance.new("Animation")
stunanim.AnimationId = "rbxassetid://15498448298"
while true do
local boss = script.Parent
for i,player in pairs(game.Players:GetPlayers()) do
if (boss:WaitForChild("HumanoidRootPart").Position - player.Character.HumanoidRootPart.Position).magnitude < 25 then
if stompwait == false then
boss.Humanoid.WalkSpeed =2
local loadedstompanim = boss.Humanoid:LoadAnimation(stompanim)
loadedstompanim:Play()
local function createdebris(dirt)
local dirt = Instance.new("Part")
dirt.Name = "Dirt"
dirt.Parent = workspace
dirt.CanCollide = true
dirt.Position = boss["Left Leg"].Position
dirt.Anchored = false
dirt.Size = Vector3.new(math.random(4,10),math.random(4,10),math.random(4,10))
dirt.AssemblyLinearVelocity = Vector3.new(math.random(50,100),math.random(50,100),math.random(50,100))
dirt.Color = workspace.Baseplate.Color
end
createdebris(Instance.new("Part"))
createdebris(Instance.new("Part"))
createdebris(Instance.new("Part"))
player.Character.Humanoid.Health -= 30
player.Character:SetAttribute("Stunned",true)
local loadeedstunanim = player.Character.Humanoid:LoadAnimation(stunanim)
loadeedstunanim.Looped = true
wait(.5)
loadeedstunanim:Play()
player.Character.Humanoid.WalkSpeed = 0
wait(4)
loadeedstunanim:Stop()
player.Character.Humanoid.WalkSpeed = 16
player.Character:SetAttribute("Stunned",false)
for i,v in pairs(workspace:GetChildren()) do
if v.Name == "Dirt" then
v:Destroy()
end
end
boss.Humanoid.WalkSpeed = 16
stompwait = true
wait(stompdebounce)
stompwait = false
end
end
end
wait(1)
end
local script
wait(.5)
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://15268336493"
local animtrack = humanoid:LoadAnimation(animation)
local debouncewait = false
local debounce = 2
game.UserInputService.InputEnded:Connect(function(input, gpe)
local stunned = player:GetAttribute("Stunned")
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if debouncewait == false and stunned == false or debouncewait == false and stunned == nil then
debouncewait= true
print(stunned)
print("clicked")
animtrack:Play()
game.ReplicatedStorage.slashsfx:Play()
game.ReplicatedStorage.slash1remote:FireServer()
wait(0.25)
game.ReplicatedStorage.slashsfx:Play()
game.ReplicatedStorage.slash2remote:FireServer()
wait(0.25)
game.ReplicatedStorage.slashsfx:Play()
game.ReplicatedStorage.slash3remote:FireServer()
wait(debounce)
debouncewait = false
end
end
end)
Thank you in advance!
Also the attribute appears in both local and server, so I don’t understand why it prints nil in local.