Hey, I made a stun script and it’s to be cloned into a part then deleted after 4 seconds
Problem is if someone runs into the block last second the stun becomes permanent because the script is deleted with the part
local part = script.Parent
local gui = script.StunGUI
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://11273357512"
anim.Parent = script
local function Stun(player)
local hum = player.Character:FindFirstChild("Humanoid")
if anim then
StunAnim = hum:LoadAnimation(anim)
end
gui.ImageLabel.ImageTransparency = 1
local guiClone = gui:Clone()
guiClone.Parent = hum.Parent:FindFirstChild("HumanoidRootPart")
local guiTween = game.TweenService:Create(guiClone.ImageLabel,TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{ImageTransparency = 0})
local guiFade = game.TweenService:Create(guiClone.ImageLabel,TweenInfo.new(0.5,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{ImageTransparency = 1})
local Stun = Instance.new("BoolValue")
Stun.Name = "Stun"
Stun.Parent = player
guiTween:Play()
StunAnim:Play()
hum.WalkSpeed = 0
hum.JumpPower = 0
game.Debris:AddItem(Stun,4)
wait(4)
guiFade:Play()
StunAnim:Stop()
hum.WalkSpeed = 16
hum.JumpPower = 50
end
local deb = false
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid",true) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
print("found")
if not player:FindFirstChild("Stun") and not deb then
deb = true
print("stunning...")
Stun(player)
deb = false
end
end
end)