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

Play sound onTouch only works in studio. Why and how can I fix it?

Asked by 6 years ago

I wrote this script while I was in studio and it worked when I tested it (In studio) but when I tested it out in the actual game it didn't work. Can someone please help me fix this or give me advice on how I can fix it.

Script:

local SP = script.Parent

function onTouch(hit)
    hit.Parent.Humanoid.CoinCollect:Play()
    end

    script.Parent.Touched:connect(onTouch)
0
What was the error? killer08932 149 — 6y
0
And what is the script supposed to do? fluffyXY52 0 — 6y
0
It was supposed to play a sound when you collect a coin. killer08932 149 — 6y
0
I think. killer08932 149 — 6y
View all comments (5 more)
0
I have no idea how this could not work... fluffyXY52 0 — 6y
0
do you have it in the right area in the Workspace? fluffyXY52 0 — 6y
0
There's a Humanoid placed in StarterPlayer, inside the Humanoid there is an Audio. When the player touches the coin (part) it plays the audio inside the Humanoid. Michael_TheCreator 166 — 6y
0
The script in question is placed inside the coin. Michael_TheCreator 166 — 6y
0
I do things in an abstract way, sorry for the confusion guys. Michael_TheCreator 166 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

The Best Answer and I promise u this will help! Click F9 while running the game to see your errors or use output window to see any errors relating to the game. That is how I solve my studio but not in game errors. If this was the best answer, click accept answer. Good Luck with your game!

1
Or he could just check the output... 0HappyManDudeguy0 15 — 6y
0
yeah same thing XD LeaderAssassinNinja 69 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

If this script is inside the coin, you don't need the audio to play from the Humanoid.

function onTouch(hit)  
script.Parent.Sound:Play()  -- Whatever the audio file is named, "Sound" "Coin" etc.
end 
script.Parent.Touched:connect(onTouch)
0
The coins gets deleted when it is collected, so the sound won't play if I do it this way. Michael_TheCreator 166 — 6y
0
Add a wait before the coin disappears. :) Never2Humble 90 — 6y
0
Touch. Play(). Wait(2). SP:Remove() Never2Humble 90 — 6y

Answer this question