local M=false local N=game.ReplicatedStorage.Mode game.ReplicatedStorage.Stun.OnServerEvent:Connect(function(N,Z)if Z then if Z:FindFirstAncestorOfClass("\077\111\100\101\108")then local N=Z:FindFirstAncestorOfClass("\077\111\100\101\108")if N then if N:FindFirstChild("\066\101\097\114")then if not M then local Z=Instance.new("\066\111\111\108\086\097\108\117\101")Z.Name="\083\116\117\110\110\101\100"Z.Parent=N game.ReplicatedStorage.Announcement:FireAllClients("\080\105\103\103\121 \105\115 \103\111\110\101 \102\111\114 \050\048 \115\101\099\111\110\100\115")N.Torso.Script.Disabled=true if N:FindFirstChild("\085\112\112\101\114\084\111\114\115\111")then local Z=(N:FindFirstChild("\072\117\109\097\110\111\105\100")):LoadAnimation(game.ReplicatedStorage.StunnedR15)M=true N.Humanoid.WalkSpeed=0 N.Humanoid.JumpPower=0 Z:Play()wait(20)Z:Stop()N.Humanoid.WalkSpeed=14 N.Humanoid.JumpPower=20 N.Torso.Script.Disabled=false M=false else local Z=(N:FindFirstChild("\072\117\109\097\110\111\105\100")):LoadAnimation(game.ReplicatedStorage.Stunned)M=true N.HumanoidRootPart.Anchored=true N.Animate.Disabled=true N.Humanoid.WalkSpeed=0 N.Humanoid.JumpPower=0 Z:Play()wait(20)N.HumanoidRootPart.Anchored=false N.Animate.Disabled=false Z:Stop()N.Humanoid.WalkSpeed=14 N.Humanoid.JumpPower=20 N.Torso.Script.Disabled=false M=false end;(N:FindFirstChild("\083\116\117\110\110\101\100")):Destroy()end end end end end end)


local debounce = false

local Gamemode = game.ReplicatedStorage.Mode

game.ReplicatedStorage.Stun.OnServerEvent:Connect(function(plr,target)
	if target then
		if target:FindFirstAncestorOfClass("Model") then
			-- Check to see if clicked model is a real player
			local piggy = target:FindFirstAncestorOfClass("Model")

			if piggy then
				if piggy:FindFirstChild("Bear") then -- Check to see if it is actually Piggy or just another contestant
					if not debounce then

						local stunTag = Instance.new("BoolValue")
						stunTag.Name = "Stunned"
						stunTag.Parent = piggy

						game.ReplicatedStorage.Announcement:FireAllClients("Piggy is gone for 20 seconds")
						piggy.Torso.Script.Disabled = true
						if piggy:FindFirstChild("UpperTorso") then
							local anim = piggy:FindFirstChild("Humanoid"):LoadAnimation(game.ReplicatedStorage.StunnedR15)
							debounce = true
							-- Freeze piggy by setting walkspeed to 0
							piggy.Humanoid.WalkSpeed = 0
							piggy.Humanoid.JumpPower = 0
							anim:Play()
							wait(20) -- wait 20 sec before enabling walkspeed again to 14 and then setting debounce to false so
							-- that the piggy can be stunned again
							anim:Stop()
							piggy.Humanoid.WalkSpeed = 14
							piggy.Humanoid.JumpPower = 20
							piggy.Torso.Script.Disabled = false
							debounce = false
						else
							local anim = piggy:FindFirstChild("Humanoid"):LoadAnimation(game.ReplicatedStorage.Stunned)
							debounce = true
							-- Freeze piggy by setting walkspeed to 0
							piggy.HumanoidRootPart.Anchored = true
							piggy.Animate.Disabled = true
							piggy.Humanoid.WalkSpeed = 0
							piggy.Humanoid.JumpPower = 0
							anim:Play()
							wait(20) -- wait 20 sec before enabling walkspeed again to 14 and then setting debounce to false so
							-- that the piggy can be stunned again
							piggy.HumanoidRootPart.Anchored = false
							piggy.Animate.Disabled = false
							anim:Stop()
							piggy.Humanoid.WalkSpeed = 14
							piggy.Humanoid.JumpPower = 20
							piggy.Torso.Script.Disabled = false
							debounce = false	
						end
						-- Enable debounce so stun effect cannot be applied again for 20 seconds

						piggy:FindFirstChild("Stunned"):Destroy() -- Delete stunned tag so we can tell from other scripts that the
						-- piggy is no longer stunned.
					end
				end
			end		
		end
	end
end)
