Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how to make this script work inside a character ?

Hello, I'm a beginner (sorry if I don't have the right terms) I have a game or among the players, a "Killer" is selected and I would like this killer to make a sound but not all the time. and I have find a solution.

-- create a sound
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://4515583231"
sound.Looped = false

wait(15)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- true, false

wait(16)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- false, true

wait(15)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- true, false

this script is inside a "Sound" in the Workspace, it works very well as I want it, I would like it to work also when I insert it in my character, but I don't know what to replace :

local sound = Instance.new("Sound", game.Workspace)

to make the sound work in my character when my character spawns.

Thank you for your answers !

1 answer

I have two answers, both of which are ServerScripts and should be placed in the character, a recommended place would be game.StarterPlayer.StarterCharacterScripts. I also cleaned up your code a bit, removing any unnecessary bits.

Answer 1:

local sound = Instance.new("Sound", script.Parent:WaitForChild("Head"))
sound.SoundId = "rbxassetid://4515583231"

wait(15)
sound:Play()
print(sound.IsPlaying, sound.IsPaused)

wait(16)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused)

wait(15)
sound:Play()
print(sound.IsPlaying, sound.IsPaused)

Answer 2:

local sound = Instance.new("Sound", script.Parent:WaitForChild("Head"))
sound.SoundId = "rbxassetid://4515583231"

wait(15)
sound:Play()
print(sound.IsPlaying, sound.IsPaused)

wait(16)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused)

wait(15)
sound:Play()
print(sound.IsPlaying, sound.IsPaused)

No problem from Canada!

1 comment

0

if I put it in the StarterPlayer, won't it make it work for all players ? Because my "killer" character is placed in ServerStorage, and I would like the sound to play with him.. maybe i misunderstood?

This discussion is preserved as it was. New answers, comments, and votes are closed.