How did i will even do it?

i’ve been tried to make a new block system.

script for creaing hitbox of block:

local blockevent = game:GetService("ReplicatedStorage").Events.Block
local player = game.Players.LocalPlayer

blockevent.OnServerEvent:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local humanoid = char:WaitForChild("Humanoid")
	local rootpart = char:WaitForChild("HumanoidRootPart")
	local hitbox = Instance.new("Part")
	hitbox.Name = "BlockHitbox"
	hitbox.Size = Vector3.new(2,3,1.4)
	hitbox.Parent = rootpart
	hitbox.CFrame = rootpart.CFrame + (rootpart.CFrame.lookVector * 2.1) 
	hitbox.CanCollide = false
	hitbox.CanQuery = false
	hitbox.Transparency = 0
	humanoid.JumpPower = 0
	local weld = Instance.new("WeldConstraint", hitbox)
	weld.Part0 = hitbox
	weld.Part1 = hitbox.Parent
end)

part of script where checking if hitbox of block touching:

for v, part in pairs(hit:GetChildren()) do
	if v == "BlockHitbox" and part.Parent ~= "Hitbox" then
		dashevent:FireClient(player, results)
		return
	end
end

i dont understand what i should do, the part of script where checking if hitbox of block touching dont work, no errors on output, but no checking (it still hitting person even if he block attack). maybe someone know how to do it better, or fix it?

Problem: It is not checked whether the hitbox touched a block with a regular hitbox.
Preferably, if there is another way to make it easier, and it will also use the block hitbox, tell me about it (because I want to repeat the block system as in the strongest battlegrounds).

for reference, in the strongest battlegrounds, if you pressed F (block), then you will block the attack if the enemy was in front, but if the enemy is behind, he will be able to hit you

is it in a server side script?

theres both scripts is a server side

for v, part in pairs(hit:GetTouchingParts()) do
	if v == "BlockHitbox" and part.Parent ~= "Hitbox" then
		dashevent:FireClient(player, results)
		return
	end
end

you were getting the children instead of the touching parts

localplayer can only be access in a local script

I accidentally added this variable, as can be seen in when the event arrives to the server, the player variable gets from the local script

it still doesn’t work if the player has placed a block.
He’s still taking damage

you still cant get localplayer in a server script regardless of if you replace the variable later on

youll still get an error

LOL OK OK IF WE WANT ADDITION:

local script OF BLOCK RAHHHHH:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = script.Parent.Parent:WaitForChild("Humanoid")
local rootpart = script.Parent.Parent:WaitForChild("HumanoidRootPart")
local animationController = game:GetService("Players").LocalPlayer.Character:WaitForChild("Humanoid"):WaitForChild("Animator")
local UIS = game:GetService("UserInputService")

--block
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://15184008907" -- замените на свой AnimationId
local animationTrack = animationController:LoadAnimation(animation)
local blockevent = game:GetService("ReplicatedStorage").Events.Block
--clicks
local clickremote = game:GetService("ReplicatedStorage").Events.M1Event
local debounce = false
--end

UIS.InputBegan:Connect(function(key, typing)
	if typing then return end
	if key.KeyCode == Enum.KeyCode.F then
		if humanoid.WalkSpeed ~= 0 then
			animationTrack:Play()
			blockevent:FireServer(player)
			humanoid.WalkSpeed = 2
		end
    end
end)

GOT IT?

im too tired to deal with you not being able to understand what localplayer is

someone else please help this person
thank you

1 Like

What’s the difference? The hitbox is created anyway. Plus, it has nothing to do with my problem.

in fact the rest of ur script will not run due to the error lol

1 Like

write down what error is shown in the console
Maybe I forgot to throw something off

I dont understand u want me to show u what error will appear ???

1 Like

yeah. which error showing up on console (output)?

idk but can u explain more deeply this part :

for v, part in pairs(hit:GetChildren()) do
	if v == "BlockHitbox" and part.Parent ~= "Hitbox" then
		dashevent:FireClient(player, results)
		return
	end
end

what is results and what is hit, how can we help u if u give us magical variable, u could maybe show us the entire script and then we would be able to help u, else part.Parent ~= “Hitbox” will always be true cuz a instance cannot be a string
Hope it helped !

1 Like
for v, part in pairs(hit:GetChildren()) do
	if v == "BlockHitbox" and part.Parent ~= "Hitbox" then
		dashevent:FireClient(player, results)
		return
	end
end

explaining: first stroke - we get whether the enemy has a BlockHitbox (hit == HumanoidRootPart), second stroke: we checking if v it’s a hit:GetChildren() == BlockHitbox, and checking if touching part is a Hitbox of dash ability. third stroke - fire a client with a results (if results is good - stop a dash).

1 Like

I really hope that everything is clear, I’m bad at English

1 Like