Why my combat system is hitting the current player?

also, the hitbox is not working, it don’t hit the dummys

Roblox Official Wiki Link - Animator | Documentation - Roblox Creator Hub

It is recommended to :LoadAnimation() for players’ characters in Client Side only → LocalScript
You only use :LoadAnimation() on NonPlayerCharacters in Server Side

3 Likes

idk, the animation still works, but thanks anyways

edit: … just a question, what is that:
Screenshot_2
‘-’

also, the hitbox don’t work idk why, i didn’t get any errors

edit: oh nvm look: Players.Heitorsonic123508.Backpack.Combate.Script:22: attempt to index nil with ‘FindFirstChild’

after i changed this line:

local victimHumanoid = victimCharacter:FindFirstChild(“Humanoid”)

Usually I see a sword script to connect Touched event when player is swinging their sword
Rather than creating Hitbox as a new Part, can you do this?

local arma = script.Parent
local jogador = arma.Parent
local blade = arma.Blade --> Name the blade part as Blade
...

function CriarHitbox()
	local touchConnection = blade.Touched:Connect(function(hit)
		local victimCharacter: Model = hit:FindFirstAncestorOfClass("Model")
		local victimHumanoid: Humanoid = victimCharacter and victimCharacter:FindFirstChildOfClass("Humanoid")
		if victimCharacter ~= personagem then -- personagem refers to your character
			victimHumanoid:TakeDamage(10)
			CanHit = false
			task.wait(0.3)
			CanHit = true
		end
	end)
	task.wait(0.15)
	touchConnection :Disconnect()
2 Likes

bro, i don’t want a sword, i want to make combat (fists) bruh

but i appreciate what did you wanted to do, but okay.

Rename it as Fist?

If you want the hitbox to be in front of the player’s humanoid root part with Size (5,5,5)

You may be better off using workspace:GetPartsInPart() or workspace:GetPartsInBound() instead of just Touched, in term of efficiency and performance.

3 Likes

um, what is this gonna help me, first of all, i don’t know absolutely nothing about this thing, second, i just want to make a simple combat fist but i want to when collide, it just don’t do damage in the current player, just on the enemy. because i have like, animations and all the thingys

@DarkMatterMU is right. GetPartsInPart is a lot better in every single aspect in my opinion too, for your current issue however, you just need to check if hit.Parent is equal to ur character, if it is then return end

2 Likes

now, i’m not just, like, a beggar but, can you just give me a simple example code on how can i make that?

local Workspace = game:GetService("Workspace")

local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 15, 0)
part.Orientation = Vector3.new(0, 90, 0)
part.BrickColor = BrickColor.new("Bright green")
part.Parent = Workspace

local otherPart = Instance.new("Part")
otherPart.Name = "OtherPart"
otherPart.Anchored = true
otherPart.Position = Vector3.new(0, 15, 0)
otherPart.BrickColor = BrickColor.new("Bright red")
otherPart.Parent = Workspace

local filter = OverlapParams.new()
filter.FilterType = Enum.RaycastFilterType.Blacklist 
filter.FilterDescendantsInstances = { otherPart }

local foundParts = Workspace:GetPartsInPart(part, filter)
print(foundParts)
1 Like

um… UHHHHHHHH, is this simple? ok, anyways, i think i’m actually a beginner

also, what is that? filter.FilterDescendantsInstances = { otherPart }

It’s basically a filter, everything inside that table will NOT be returned by GetPartsInPart, meaning when you print it, you will see everything else inside the part, except otherPart

1 Like

oh, i see, but HOW IN THE WORLD am i’m gonna use that in my combat system???

You will simply have to learn how to use it in different scenarios, but as i said you aren’t required to use it, your original idea should still work (w maybe a couple issues)

2 Likes

bro, i just want to tell a thing, THERE’S NO TUTORIALS ON YOUTUBE, like how

It’s difficult to help you if we don’t know how your structure of the game is laid out.

Is it a server script?
Is there a local script inside of a tool that fires a remote event to the server script?

Also, what they were saying is if whatever your tool is hits a part, it should check what the parent of that part is, if the parent of that part is equal to the player that was swinging it, it should return end, which basically means it just prevents it from damaging the player, you would then add an else statement that would contain the code to damage the actual enemy(or thing you want to damage)

To tell the script who the player is (who we don’t want to hit) you simply need to send the player through the remote event that is firing as an argument to the server script. which I assume we have a local script in the tool that does that but again it’s difficult to tell what we are working with here.

Also, when we are sending you links(documentation) to what you don’t understand, for example, GetPartsinPart, it’s there so you can read about it to understand it, you could also go to youtube and attempt to find a tutorial on what we sent you documentation on instead, and follow the tutorial to try to better understand that
Then apply what you learnt from the documentation or tutorial to your current code. :slight_smile:

1 Like

You can try using a spatial query hitbox module like muchacho hitbox (https://create.roblox.com/store/asset/9645263113/MuchachoHitbox)— and there is a video on youtube if you want a tutorial. It casts the hitbox on a serverscript aswell, which may be helpful to u even if you dont use the module

3 Likes

@Polynovuh, @Phoenix_Ascended, Thanks for the help! I appreciate your two helps, i’m gonna try the @Polynovuh one. But thanks anyway guys!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.