How to make a good stun for combats

I want to make a stuns that make player unable to punch back or block when they got hit.
Also i tried this with BoolValue method the one that you use BoolValue to make stun i tried it and it’s gave a weird bug it’s says ServerScriptService.Hitbox:31: attempt to index nil with ‘Value’ i can’t change the value of it. And also if you know how to disable all player’s control like disable everything keyboard, mouse , etc please tell me.

Could you possibly send the script?

1 Like

local GG = game:GetService(“Debris”)
local Hitbox1 = game.ServerStorage:WaitForChild(“Part”)
game.ReplicatedStorage.Hit.OnServerEvent:Connect(function(player)
local Scripta = script:WaitForChild(“Animation”)
local Rep = game.ReplicatedStorage.P1
local Rep2 = game.ReplicatedStorage.P2
local Char = player.Character
local CharHuRoot = Char:WaitForChild(“HumanoidRootPart”)
local Hitbox2 = Hitbox1:Clone()
Hitbox2.CFrame = Char.HumanoidRootPart.CFrame + Char.HumanoidRootPart.CFrame.LookVector * 0.8
Hitbox2.Parent = Char.HumanoidRootPart
local Huma = Char.Humanoid
local weld = Instance.new(“WeldConstraint”)
weld.Part0 = Char.HumanoidRootPart
weld.Part1 = Hitbox2
weld.Parent = weld.Part0----
local Debounce = false
local HH = script:WaitForChild(“Animation2”)
local JJ = Huma:LoadAnimation(HH)

	Hitbox2.Touched:Connect(function(Hit)
		local Char = player.Character
		local Hume = Hit.Parent:FindFirstChild("Humanoid")
		local HumeRooPa = Hit.Parent:FindFirstChild("HumanoidRootPart")
		local UU = Hit.Parent:FindFirstChild("CanAttack")
		local player1 = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent) or not Char
		if Hit.Parent == Char or Hit.Parent == nil then return end
		if Hit.Parent:FindFirstChild("Accessory") then
			return nil
		end
		if UU.Value == true then
			if player1 and Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("HumanoidRootPart") and  Hit.Parent:IsA("Model") and Hit.Parent ~= nil and Hit.Parent.Humanoid.Health > 0 then

				Rep:FireClient(player1)
				local HH1 = Instance.new("BoolValue")
				HH1.Parent = Hit.Parent
				HH1.Name = "Stun"
				game.Debris:AddItem(HH1,3)
				print("Hi")--3
				local Hu1 = Hit.Parent:WaitForChild("Humanoid")
				local Bovy = Instance.new("BodyVelocity")
				Bovy.Parent = Hit.Parent:WaitForChild("HumanoidRootPart")
				game.Debris:AddItem(Bovy,0.1)
				Bovy.Velocity = Char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 38
				Bovy.MaxForce =  Vector3.new(10000,100000,10000)
				game.Debris:AddItem(Bovy,0.1)
				Hume:TakeDamage(15)
				Hitbox2:Destroy()
				Debounce = false
				weld.Part1:Destroy()
				Hit.Parent.Humanoid:LoadAnimation(Scripta):Play()
				Char.Humanoid.Died:Connect(function()
					Rep2:FireClient(player1)
				end)
			end

			if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("HumanoidRootPart") and Hit.Parent:IsA("Model") and Hit.Parent ~= nil and Hit.Parent.Humanoid.Health > 0 then

				local Hu1 = Hit.Parent:WaitForChild("Humanoid")
				Hu1:LoadAnimation(Scripta):Play()
				local Bovy = Instance.new("BodyVelocity")
				Bovy.MaxForce = Vector3.new(10000,100000,10000)
				Bovy.Parent = Hit.Parent:WaitForChild("HumanoidRootPart")
				game.Debris:AddItem(Bovy,0.1)
				Bovy.Velocity = Char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 65
				Hume:TakeDamage(15)
				Hitbox2:Destroy()
				Debounce = false
				weld.Part1:Destroy()

			end
		end
	end)
wait(0.1)
weld.Part1:Destroy()

end)

How? Can you give me some examples?

Which line of code adds the CanAttack value to the Hitbox?

That’s a seperate script But here it is
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local clone = script.CanAttack:Clone()
clone.Parent = char
clone.Value = true
end)
end)

Add the Can Attack value to the script and then try this:


game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local clone = script:WaitForChild("CanAttack"):Clone()
clone.Parent = char
clone.Value = true
end)
end)
local GG = game:GetService(“Debris”)
local Hitbox1 = game.ServerStorage:WaitForChild(“Part”)
game.ReplicatedStorage.Hit.OnServerEvent:Connect(function(player)
local Scripta = script:WaitForChild(“Animation”)
local Rep = game.ReplicatedStorage.P1
local Rep2 = game.ReplicatedStorage.P2
local Char = player.Character
local CharHuRoot = Char:WaitForChild(“HumanoidRootPart”)
local Hitbox2 = Hitbox1:Clone()
Hitbox2.CFrame = Char.HumanoidRootPart.CFrame + Char.HumanoidRootPart.CFrame.LookVector * 0.8
Hitbox2.Parent = Char.HumanoidRootPart
local Huma = Char.Humanoid
local weld = Instance.new(“WeldConstraint”)
weld.Part0 = Char.HumanoidRootPart
weld.Part1 = Hitbox2
weld.Parent = weld.Part0----
local Debounce = false
local HH = script:WaitForChild(“Animation2”)
local JJ = Huma:LoadAnimation(HH)

	Hitbox2.Touched:Connect(function(Hit)
		local Char = player.Character
		local Hume = Hit.Parent:FindFirstChild("Humanoid")
		local HumeRooPa = Hit.Parent:FindFirstChild("HumanoidRootPart")
		local UU = Hit.Parent:FindFirstChild("CanAttack")
		local player1 = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent) or not Char
		if Hit.Parent == Char or Hit.Parent == nil then return end
		if Hit.Parent:FindFirstChild("Accessory") then
			return nil
		end
		if UU.Value == true then
			if player1 and Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("HumanoidRootPart") and  Hit.Parent:IsA("Model") and Hit.Parent ~= nil and Hit.Parent.Humanoid.Health > 0 then

				Rep:FireClient(player1)
				local HH1 = Instance.new("BoolValue")
				HH1.Parent = Hit.Parent
				HH1.Name = "Stun"
				game.Debris:AddItem(HH1,3)
				print("Hi")--3
				local Hu1 = Hit.Parent:WaitForChild("Humanoid")
				local Bovy = Instance.new("BodyVelocity")
				Bovy.Parent = Hit.Parent:WaitForChild("HumanoidRootPart")
				game.Debris:AddItem(Bovy,0.1)
				Bovy.Velocity = Char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 38
				Bovy.MaxForce =  Vector3.new(10000,100000,10000)
				game.Debris:AddItem(Bovy,0.1)
				Hume:TakeDamage(15)
				Hitbox2:Destroy()
				Debounce = false
				weld.Part1:Destroy()
				Hit.Parent.Humanoid:LoadAnimation(Scripta):Play()
				Char.Humanoid.Died:Connect(function()
					Rep2:FireClient(player1)
				end)
			end

			if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("HumanoidRootPart") and Hit.Parent:IsA("Model") and Hit.Parent ~= nil and Hit.Parent.Humanoid.Health > 0 then

				local Hu1 = Hit.Parent:WaitForChild("Humanoid")
				Hu1:LoadAnimation(Scripta):Play()
				local Bovy = Instance.new("BodyVelocity")
				Bovy.MaxForce = Vector3.new(10000,100000,10000)
				Bovy.Parent = Hit.Parent:WaitForChild("HumanoidRootPart")
				game.Debris:AddItem(Bovy,0.1)
				Bovy.Velocity = Char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 65
				Hume:TakeDamage(15)
				Hitbox2:Destroy()
				Debounce = false
				weld.Part1:Destroy()

			end
		end
	end)
wait(0.1)
weld.Part1:Destroy()


end)

It’s says
14:57:19.938 ServerScriptService.Hitbox:38: attempt to index nil with ‘Value’ - Server - Hitbox:38
14:57:19.938 Stack Begin - Studio
14:57:19.938 Script ‘ServerScriptService.Hitbox’, Line 38 - Studio - Hitbox:38
14:57:19.938 Stack End - Studio

did you add the can attack value to the script?

I did
image
like this right?


here’s the eror

	local UU = Hit.Parent:FindFirstChild("CanAttack")

Instead of FindFirstChild, try WaitForChild and if it warns or not, tell me.

It’s work fine but player can still punch back while they’re stuned.

Show me the fighting script because I think this has something to do with it.

Okay
Here’s the Hitbox script
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local clone = script:WaitForChild(“CanAttack”):Clone()
clone.Parent = char
clone.Value = true
end)
end)
local GG = game:GetService(“Debris”)
local Hitbox1 = game.ServerStorage:WaitForChild(“Part”)
game.ReplicatedStorage.Hit.OnServerEvent:Connect(function(player)
local Scripta = script:WaitForChild(“Animation”)
local Rep = game.ReplicatedStorage.P1
local Rep2 = game.ReplicatedStorage.P2
local Char = player.Character
local CharHuRoot = Char:WaitForChild(“HumanoidRootPart”)
local Hitbox2 = Hitbox1:Clone()
Hitbox2.CFrame = Char.HumanoidRootPart.CFrame + Char.HumanoidRootPart.CFrame.LookVector * 0.8
Hitbox2.Parent = Char.HumanoidRootPart
local Huma = Char.Humanoid
local weld = Instance.new(“WeldConstraint”)
weld.Part0 = Char.HumanoidRootPart
weld.Part1 = Hitbox2
weld.Parent = weld.Part0----
local Debounce = false
local HH = script:WaitForChild(“Animation2”)
local JJ = Huma:LoadAnimation(HH)

Hitbox2.Touched:Connect(function(Hit)
	local Char = player.Character
	local Hume = Hit.Parent:FindFirstChild("Humanoid")
	local HumeRooPa = Hit.Parent:FindFirstChild("HumanoidRootPart")
	local UU = Hit.Parent:WaitForChild("CanAttack")
	local player1 = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent) or not Char
	if Hit.Parent == Char or Hit.Parent == nil then return end
	if Hit.Parent:FindFirstChild("Accessory") then
		return nil
	end
	if UU.Value == true then
		if player1 and Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("HumanoidRootPart") and  Hit.Parent:IsA("Model") and Hit.Parent ~= nil and Hit.Parent.Humanoid.Health > 0 then

			Rep:FireClient(player1)
			local HH1 = Instance.new("BoolValue")
			HH1.Parent = Hit.Parent
			HH1.Name = "Stun"
			game.Debris:AddItem(HH1,3)
			print("Hi")--3
			local Hu1 = Hit.Parent:WaitForChild("Humanoid")
			local Bovy = Instance.new("BodyVelocity")
			Bovy.Parent = Hit.Parent:WaitForChild("HumanoidRootPart")
			game.Debris:AddItem(Bovy,0.1)
			Bovy.Velocity = Char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 38
			Bovy.MaxForce =  Vector3.new(10000,100000,10000)
			game.Debris:AddItem(Bovy,0.1)
			Hume:TakeDamage(15)
			Hitbox2:Destroy()
			Debounce = false
			weld.Part1:Destroy()
			Hit.Parent.Humanoid:LoadAnimation(Scripta):Play()
			Char.Humanoid.Died:Connect(function()
				Rep2:FireClient(player1)
			end)
		end

		if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("HumanoidRootPart") and Hit.Parent:IsA("Model") and Hit.Parent ~= nil and Hit.Parent.Humanoid.Health > 0 then

			local Hu1 = Hit.Parent:WaitForChild("Humanoid")
			Hu1:LoadAnimation(Scripta):Play()
			local Bovy = Instance.new("BodyVelocity")
			Bovy.MaxForce = Vector3.new(10000,100000,10000)
			Bovy.Parent = Hit.Parent:WaitForChild("HumanoidRootPart")
			game.Debris:AddItem(Bovy,0.1)
			Bovy.Velocity = Char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 65
			Hume:TakeDamage(15)
			Hitbox2:Destroy()
			Debounce = false
			weld.Part1:Destroy()

		end
	end
end)
wait(0.1)
weld.Part1:Destroy()

end)
And this one is ragdoll script

local RagdollEvent = game.ReplicatedStorage.Ragdoll
local UnRagdollEvent = game.ReplicatedStorage.Unragdoll

RagdollEvent.OnServerEvent:Connect(function(Player)
for i,v in pairs(Player.Character:GetDescendants()) do
if v:IsA(“Motor6D”) and v.Parent.Name ~= “HumanoidRootPart” then
local Socket = Instance.new(“BallSocketConstraint”)
local a1 = Instance.new(“Attachment”)
local a2 = Instance.new(“Attachment”)
a1.Parent = v.Part0
a2.Parent = v.Part1
Socket.Parent = v.Parent
Socket.Attachment0 = a1
Socket.Attachment1 = a2
a1.CFrame = v.C0
a2.CFrame = v.C1
Socket.LimitsEnabled = true
Socket.TwistLimitsEnabled = true
v:Destroy()
end
end
Player.Character.Humanoid.RequiresNeck = false
Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)

end)

UnRagdollEvent.OnServerEvent:Connect(function(Player)
for i,v in pairs(Player.Character:GetDescendants()) do
if v:IsA(“BallSocketConstraint”) then
v.UpperAngle = 0
v.TwistUpperAngle = 0
v.TwistLowerAngle = 0
local Joints = Instance.new(“Motor6D”,v.Parent)
Joints.Part0 = v.Attachment0.Parent
Joints.Part1 = v.Attachment1.Parent
Joints.C0 = v.Attachment0.CFrame
Joints.C1 = v.Attachment1.CFrame
v:Destroy()
end
end
Player.Character.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end)
And this one is Local Script
local Animation = script:WaitForChild(“Animation”)

local Animation2 = script:WaitForChild(“Animation2”)

local Player = game:GetService(“Players”).LocalPlayer

local Char = Player.Character

local Human = Char:WaitForChild(“Humanoid”)

local Hit = game.ReplicatedStorage:WaitForChild(“Hit”)

local HumanRoot = Char:WaitForChild(“HumanoidRootPart”)

local UIS = game:GetService(“UserInputService”)

local cooldown = 5

local Debounce = false

if Human.Died then

script.Disabled = true

end

UIS.InputBegan:Connect(function(input,IsTyping)

if not IsTyping and not Debounce then

if input.KeyCode == Enum.KeyCode.F then

Hit:FireServer()

Debounce = true

wait(1)

Debounce = false

end

end

end)

Is the fighting script a local or server script?

local and server and also a ragdoll script

So it’s a local script?(ignoring the ragdoll script)

Yes It is a local script. And what do you mean by fighting script?

By fighting script I mean the script you use to make the player combat.

This is fighting script i only have this one
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local clone = script:WaitForChild(“CanAttack”):Clone()
clone.Parent = char
clone.Value = true
end)
end)
local GG = game:GetService(“Debris”)
local Hitbox1 = game.ServerStorage:WaitForChild(“Part”)
game.ReplicatedStorage.Hit.OnServerEvent:Connect(function(player)
local Scripta = script:WaitForChild(“Animation”)
local Rep = game.ReplicatedStorage.P1
local Rep2 = game.ReplicatedStorage.P2
local Char = player.Character
local CharHuRoot = Char:WaitForChild(“HumanoidRootPart”)
local Hitbox2 = Hitbox1:Clone()
Hitbox2.CFrame = Char.HumanoidRootPart.CFrame + Char.HumanoidRootPart.CFrame.LookVector * 0.8
Hitbox2.Parent = Char.HumanoidRootPart
local Huma = Char.Humanoid
local weld = Instance.new(“WeldConstraint”)
weld.Part0 = Char.HumanoidRootPart
weld.Part1 = Hitbox2
weld.Parent = weld.Part0----
local Debounce = false
local HH = script:WaitForChild(“Animation2”)
local JJ = Huma:LoadAnimation(HH)

Hitbox2.Touched:Connect(function(Hit)
	local Char = player.Character
	local Hume = Hit.Parent:FindFirstChild("Humanoid")
	local HumeRooPa = Hit.Parent:FindFirstChild("HumanoidRootPart")
	local UU = Hit.Parent:FindFirstChild("CanAttack")
	local player1 = game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent) or not Char
	if Hit.Parent == Char or Hit.Parent == nil then return end
	if Hit.Parent:FindFirstChild("Accessory") then
		return nil
	end
	if UU.Value == true then
		if player1 and Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("HumanoidRootPart") and  Hit.Parent:IsA("Model") and Hit.Parent ~= nil and Hit.Parent.Humanoid.Health > 0 then

			Rep:FireClient(player1)
			local HH1 = Instance.new("BoolValue")
			HH1.Parent = Hit.Parent
			HH1.Name = "Stun"
			game.Debris:AddItem(HH1,3)
			print("Hi")--3
			local Hu1 = Hit.Parent:WaitForChild("Humanoid")
			local Bovy = Instance.new("BodyVelocity")
			Bovy.Parent = Hit.Parent:WaitForChild("HumanoidRootPart")
			game.Debris:AddItem(Bovy,0.1)
			Bovy.Velocity = Char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 38
			Bovy.MaxForce =  Vector3.new(10000,100000,10000)
			game.Debris:AddItem(Bovy,0.1)
			Hume:TakeDamage(15)
			Hitbox2:Destroy()
			Debounce = false
			weld.Part1:Destroy()
			Hit.Parent.Humanoid:LoadAnimation(Scripta):Play()
			Char.Humanoid.Died:Connect(function()
				Rep2:FireClient(player1)
			end)
		end

		if Hit.Parent:FindFirstChild("Humanoid") and Hit.Parent:FindFirstChild("HumanoidRootPart") and Hit.Parent:IsA("Model") and Hit.Parent ~= nil and Hit.Parent.Humanoid.Health > 0 then

			local Hu1 = Hit.Parent:WaitForChild("Humanoid")
			Hu1:LoadAnimation(Scripta):Play()
			local Bovy = Instance.new("BodyVelocity")
			Bovy.MaxForce = Vector3.new(10000,100000,10000)
			Bovy.Parent = Hit.Parent:WaitForChild("HumanoidRootPart")
			game.Debris:AddItem(Bovy,0.1)
			Bovy.Velocity = Char:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 65
			Hume:TakeDamage(15)
			Hitbox2:Destroy()
			Debounce = false
			weld.Part1:Destroy()

		end
	end
end)

wait(0.1)
weld.Part1:Destroy()

end)