2 Problems with attack/punch code

Hello, so i’ve made a attack system for my game. The client detects the inputs and fires an event to the server, who will then deal the damage and stuff, etc. The problems are :
-1st, The Bam/Pow thingy effect when the player hits another player/humanoid doesn’t face the player, i don’t really know how to make it work tho.
-2nd, the “elseif not Enemy” part of the code (which is supposed to check if the player is hitting a simple part like a wall instead of a humanoid) doesn’t run at all, it doesn’t even print anything.

Server Script

local function onAttackEvent(Player, ATK_Num, Hit_SFX, Fail_SFX, Woosh_SFX)
	Woosh_SFX:Play()
	local Character = Player.Character
	local Humanoid = Character:WaitForChild("Humanoid")
	local Hum_Root = Character:WaitForChild("HumanoidRootPart")
	----------------------------------------------------
	local Parameters = RaycastParams.new()
	Parameters.FilterType = Enum.RaycastFilterType.Exclude
	Parameters.FilterDescendantsInstances = {Character}
	----------------------------------------------------
	local Origin = Hum_Root.Position
	local Direction = Hum_Root.CFrame.LookVector * 5
	local Result = workspace:Raycast(Origin, Direction, Parameters)
	----------------------------------------------------
	if Result then
		local Part = Result.Instance
		local Enemy = Part.Parent:FindFirstChild("Humanoid") or Part.Parent.Parent:FindFirstChild("Humanoid")
		----------------------------------------------------
		if Enemy and Enemy:GetState() ~= Enum.HumanoidStateType.Dead then
			Hit_SFX.PlaybackSpeed = math.random(9, 11)/10
			Hit_SFX:Play()
			if ATK_Num == 1 then
				Enemy:TakeDamage(math.random(2, 4))
				local Blow_FX = Effects_FLDR.Blow:Clone()
				Blow_FX.Parent = workspace 
				Blow_FX.Position = Character:WaitForChild("LeftHand").Position 
				Tween_SVC:Create(Blow_FX, TweenInfo.new(0.25, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Size = Vector3.new(4, 0.25, 4), Transparency = 1}):Play()
				task.wait(0.5)
				Blow_FX:Destroy()
			elseif ATK_Num == 2 then
				Enemy:TakeDamage(math.random(4, 6))
				local Blow_FX = Effects_FLDR.Blow:Clone()
				Blow_FX.Parent = workspace
				Blow_FX.Orientation = Hum_Root.Orientation - Vector3.new(0, 180, 0)
				Blow_FX.Position = Character:WaitForChild("RightHand").Position 
				Tween_SVC:Create(Blow_FX, TweenInfo.new(0.25, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Size = Vector3.new(4, 0.25, 4), Transparency = 1}):Play()
				task.wait(0.5)
				Blow_FX:Destroy()
			elseif ATK_Num == 3 then
				Enemy:TakeDamage(math.random(6, 8))
				local Blow_FX = Effects_FLDR.Blow:Clone() 
				Blow_FX.Parent = workspace
				Blow_FX.Orientation = Hum_Root.Orientation - Vector3.new(0, 180, 0)
				Blow_FX.Position = Character:WaitForChild("RightFoot").Position 
				Tween_SVC:Create(Blow_FX, TweenInfo.new(0.25, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Size = Vector3.new(4, 0.25, 4), Transparency = 1}):Play()
				task.wait(0.5)
				Blow_FX:Destroy()
			end
		elseif Enemy == nil then
			print("f")
			Fail_SFX.PlaybackSpeed = math.random(9, 11)/10
			Fail_SFX:Play()
		end
	end
end

Here is an illustration of how i want the “pow” effect to appear :

But instead it appears in it’s original orientation regardless of where the player is.

2 Likes

This is a bump (&rzazqsfsqdsqfz)

2 Likes

bump again plzzzzzzzzzzzzzzzzzzzzzz

2 Likes

Hey replying since no one else did (im not really good with geometry)

maybe you could try to use

CFrame.lookAt(Blow_FX.Position, Hum_Root.Position)

but I can’t say anthing further than that since I don’t have experience in the topic.

3 Likes

yours might work, but I feel like this might aswell.

CFrame.lookAt(Blow_FX.Position, Hum_Root.Position + Direction)
2 Likes

where should i put it in the script

You should place @Mighty1964 's code where ever you are trying to make the Blow_FX face the root part.

So i just put it like that without anything behind like Blow_FX.Orientation = for example?

Thank you for the credit.

This text will be blurred

2 Likes

Not really, since we are working with CFrame objects now you should change Blow_FX’s CFrame property :+1:

I tried it and it appears in the workspace but i can’t see it in the game.

Bump qsfqzseztfeqsfdsqsfazrazrrze

How come? Can you check the position of the Blow_FX model with the explorer?

under the if statement if ATK_Num == 1 then where you have the line Blow_FX.Position = Character:WaitForChild("LeftHand").Position

replace that with these:

local Left_Hand = Character:WaitForChild("LeftHand")
Blow_FX.CFrame = Left_Hand.CFrame

if its not in the right orientation you can add onto that last line with

local Left_Hand = Character:WaitForChild("LeftHand")
Blow_FX.CFrame = Left_Hand.CFrame * CFrame.Angles(math.rad(0), math.rad(0), math.rad(0)) -- change either the x, y, or z axis with 90 or -90 and experiment until you get the correct rotation/orientation

It works good but i want it to be in the position of the hit part, because sometimes the effect appears a little too far away.

I checked it, the position was 300 something for X Y and Z, but @hotpocket285 solved this issue of position.

do you want the effect to be on your fist or the part you hit?

Well i originally wanted it to be on the fist, but it looked weird and inconsistent sometimes so now i want it to appear on the part.

you could replace that code with something like this

local Left_Hand = Character:WaitForChild("LeftHand")
Blow_FX.CFrame = CFrame.new(Result.Position, Left_Hand.Position) * CFrame.Angles(math.rad(0), math.pi, math.rad(0)) -- change either the x or z angles to 90, 180, -180, or -90 to fix rotation if it doesn't work

That fixed it, thanks. But now there’s still the other problem left.