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

Local music script?

Asked by 10 years ago

Hi robloxians, I need your help with this lil script here:

debounce = false
function onTouched(hit) 
if debounce == false then
debounce = true
local s = Instance.new("Sound") 
s.Name = "Sound" 
s.SoundId = "http://www.roblox.com/asset/?id=148101943" 
s.Volume = 1 
s.Looped = false 
s.archivable = false 

s.Parent = game.Workspace.CurrentCamera

wait(0)

s:play() 
end
end

script.Parent.Touched:connect(onTouched)

So um this music script that plays music to a player who touched it.... But something is wrong can ya tell me? I inserted this script into a part so when someone touches it the script plays music for him. I think it's something wrong with the last line maybe?

2 answers

Log in to vote
0
Answered by 10 years ago

Now this depends..

script.Parent.Touched:connect(onTouched)

This is the line I think that has gone wrong.

The script you have coded depends on what you want. When there is multiple people in the server, that line of the script will not work. Parent can only be used when there is only 1 player in the server, otherwise the script breaks and doesn't work.

Or it can play the sound on whole server, which you don't want.

script.LocalPlayer.Touched:connect(onTouched)

This line indicates that the music only plays on the LocalPlayer, it only plays for you. Not anyone else if you're in a more than 1 player server.

So, there you go. Happy days!

0
It no work :C rimvosiusLOST 5 — 10y
0
Well then sorry, I don't know any solutions other than that! :c Auroradom 25 — 10y
Ad
Log in to vote
0
Answered by
udoxas 75
10 years ago

I think the problem was that the sound was going into the camera. I edited it to go into the users PlayerGui, tested it in studio and it worked.

debounce = false
function onTouched(hit) 
if debounce == false then
debounce = true
local s = Instance.new("Sound") 
s.Name = "Sound" 
s.SoundId = "http://www.roblox.com/asset/?id=148101943" 
s.Volume = 1 
s.Looped = false 
s.archivable = false 

s.Parent = game.Players.LocalPlayer.PlayerGui

wait(0)

s:play() 
end
end

script.Parent.Touched:connect(onTouched)

Answer this question