Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont my audio play when hit.Anchored == false?

Asked by 3 years ago

So I have a script in my race car that, when this part is sticking out hits a part that is unanchored, it will play an audio saying "On your outside!" but no matter what I try, me and my friend cannot get it to work. https://gyazo.com/ab002f7edc57a0b61e47270309c7a5e6 ^ That is the picture

0
The gyazo link is the picture xWolfXtreme 2 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You have to be more specific on line 2. You are checking if hit.Parent is a player's character. There are properties in each object such as ClassName and Name. A character's class is not Body, nor is it his/her name. That's why it's best to check if hit.Parent has a child called "Humanoid" because only players in the server have Humanoids since it gives them health.

function onTouched(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        script.Parent:Play()
    end
end

script.Parent.Touched:Connect(onTouched) -- I'm puzzled about this line because on line 3, you want the script's parent to play so it is most likely a Sound. Here, you are giving this Sound a Touched event. Sounds cannot be touched and that's why they can't have Touched events. You either made a mistake on line 3 or here. Fix this too.
0
Thank you xWolfXtreme 2 — 3y
Ad

Answer this question