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)
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.
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
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)
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