I only want to make it sound when I'm shot

I only want to make it sound when I’m shot. I used a print statement to see what the conflicting part was, but it is not detected because it is a laycasting method What should I do

local part = script.Parent

part.Touched:Connect(function(hit)
	
	local P = hit
	
print("-----------------------------",P)
	
end)

8 Likes

I have no clue what you are trying to say. You need to be more clear on what the problem is and you need to proof read your writing because I see spelling errors.

2 Likes

The car tries to make a certain sound when it is hit by a bullet.
But the way the gun does damage is laycast, so it sounds when you don’t want it.

1 Like

레이캐스트가 파트에 닿아 휴머노이드 체력을 떨어뜨릴 때 내는 소리를 들려주고 싶습니다

17 Likes

Have the weapon cast some sort of state onto the car where the car would then know it has been shot, instead of just making the car produce a noise every single time it has been touched.

That’s what I want to do now
But I don’t know how to get the car to know it’s been shot because the way the gun works is laycasting
There’s nothing in the print

If you are using raycasts, you can use raycastresult.Instance to find the part it will hit.

How can I put a conditional statement here I don’t know how to use raycastresult

local part = script.Parent
local oldHealth = part.Health
local sound = workspace.metalhit

part.HealthChanged:Connect(function(health)

	if oldHealth>health then
		sound:Play()
	end
	
end)

If you want to have a sound to play when your character is damaged, perhaps this could be of use:

local player = script.Parent -- assuming this is the player's character model
local oldHealth = player.Humanoid.Health
local sound = workspace.metalhit

player.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
     if player.Humanoid.Health < oldHealth then
          sound:Play()
          oldHealth = player.Humanoid.Health
     end
end)

All I want to do is play the sound when I’m shot

If the weapon does damage, you could check if he took damage and then play the sound.

How do I check for damage with a weapon

The script snippet will play the sound when you take damage. If you getting shot causes the player to lose HP, then this should work.

If you hit something like a wall and get hurt, you can hear the sound of being shot. I’m trying to stop this

you should locate the :TakeDamage functions within your code, and and perhaps fireclient to play a hit sound specific for a bullet shot for example.

Something is created and flown in, but it is not detected by hit. I tried playing sound on takedamage, but it doesn’t work. Can you tell me in more detail

ocal function _defaultDamageCallback(system, target, amount, damageType, dealer, hitInfo, damageData)
	if target:IsA("Humanoid") then
		target:TakeDamage(amount)
		TagHumanoid(target,dealer)
		sound:Play()
		
	end
end
2 Likes

I think this video may help you to laycast: https://www.youtube.com/watch?v=b3tOR06D_HI

1 Like

literally just came here from that video
also can somebody tell me what is a layca