I am trying to figure out how to get this bullet to damage the player again

So recently, I followed a YouTube tutorial and made modifications to the script to be compatible with a work-in-progress gun framework

this particular script here doesn’t seem to deduct health to the “Humanoid”.

IT would function if it was in the ServerScriptService but that would have more problems and I sort of need to figure out how the instance can properly detect the “Humanoid” whilst avoiding the fact I need to put it in ServerScriptService.

image
The “GunServer” is where the script is located Inside the tool.

Tutorial link FYI: https://www.youtube.com/watch?v=KYH6Xv7RrwM

Does anyone have solutions?

5 Likes

So when you do

if Result.Instance.Name == "Head" then
	print("Hit through head")
	Humanoid.Health -= Damage * HeadshotBonus
else
	print("Hit other thing")
	Humanoid.Health -= Damage
end

It does not print anything? We can go from there once we know this.

That is what I am assuming is what is deducting the health.

2 Likes

Sometimes Result.Instance.Parent is unreliable if the raycast happens to hit an Accessory, so I recommend you replace it with this:

local Model = Result.Instance:FindFirstAncestorWhichIsA("Model")

if Model == nil then return end

local Humanoid = Model:FindFirstChildWhichIsA("Humanoid")

Then the rest of your code

3 Likes

Well, it does print(“Hit other thing”) without the damage output.

Sorry for the late response since I was busy with other things but

image
I am not 100% sure how I am supposed to implement it but there are like 2 active problems

  1. The ray cast slows down when near the humanoid…
  2. Still doesn’t do damage.

Not sure what’s going on tbh. I might have to switch out to a new gun system.

Sorry for the late reply, but after re-reading the script in the main topic I’m noticing you’re using Enum.RaycastFilterType.Include instead of Enum.RaycastFilterType.Exclude for the RayParams, which will result in the raycast only being able to hit the character who shot the raycast themselves

I’m unsure as to what’s causing the raycast to slow down though

1 Like

Surprisingly, I rechecked the script and the RaycastFilterType was set to Exclude.

Here’s the whole script if you want to read it.

What method are you using to find the mouse position?

So, the script works in ServerScriptService but not parented to the ServerScripts folder in the tool?

Not at all. I am not 100% sure why it only works on ServerScriptService

image
Not 100% sure if this is the the actual method to find the mouse position because like I said, this is a YouTube tutorial script.

Does the script work at all? Like do some parts of the script work but others don’t?

You need to convert it to a unit vector first before multiplying the gun range like so:

local Direction = (MousePosition - Gun.Muzzle.Attachment.WorldPosition).Unit * GunRange

I also think that the attachment’s WorldPosition meeds to be used instead of its Position since WorldPosition uses world space and Position uses object space in attachments

some parts do

it’s just that the bullet slows down when it’s near a “humanoid” and the bullet deals no damage.

Well, this just makes the bullet missing now.

Alright, I figured out where most of my problems went…

Using attachment.position, the script has no idea where or what that is so it ends up bugging out.

I guess I found my solution. But once again, thank you to those who tried to help with the problem!! :grinning:

I did mention that though, here:

Welp mb, I just didn’t understand so I just ran through the thing myself with little knowledge

I’ll make that the solution so it doesn’t like I’m claiming all the credit for myself!! :sweat_smile:

1 Like

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