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

(SOLVED) - How do I make a local sound from touching a part?

Howdy!, I am making a simple game and I have tried to do a local sound when you touch a part, however, I have not yet come to a conclusion, and I have thrown all attempts throught the window, so I am asking for help to someone more experienced that I am.

There isn't anything related to sound, yet, but I will post this code, as it might change how the sound should be made.

-- / Variables / --

local Debounce = false

-- / When Eaten / --

script.Parent.Touched:Connect(function(Plr)
if Plr.Parent:FindFirstChild('Humanoid') and Debounce == false then 
local Humanoid = Plr.Parent:FindFirstChild('Humanoid')
Debounce = true
	
		local Body1 = Humanoid:FindFirstChild('BodyDepthScale')
		local Body2 = Humanoid:FindFirstChild('BodyWidthScale')
		local Body3 = Humanoid:FindFirstChild('BodyHeightScale')
		local Head = Humanoid:FindFirstChild('HeadScale')
			 
        Body1.Value = Body1.Value + .03
	    Body2.Value = Body2.Value + .025		
        Body3.Value = Body3.Value + .02
        Head.Value = Head.Value + .015

        Humanoid.WalkSpeed = Humanoid.WalkSpeed - 0.01
        Humanoid.JumpPower = Humanoid.JumpPower - 0.031
        
script.Parent:Destroy()
end
end)
wait(10)
script.Parent:Destroy()

This one is the part script at ServerStorage that I want to make the local sound, and is cloned by a ServerScriptService Script.

If you could help me by either a script or an Idea that I haven't tried, I'll be happy to try it!

Best Regards - A novice scripter.


I did it!, Thanks to all of you, but especially to UnitedGateCompany, who assisted me with their time and effort to help make my own game.

If any of you have a similar problem, I will post the now working script below.

-- / Variables / --

local Debounce = false

-- / When Eaten / --

script.Parent.Touched:Connect(function(Chr)
if Chr.Parent:FindFirstChild('Humanoid') and Debounce == false then 
local Humanoid = Chr.Parent:FindFirstChild('Humanoid')
local Player = game.Players:GetPlayerFromCharacter(Chr.Parent)
Debounce = true
	
		local Body1 = Humanoid:FindFirstChild('BodyDepthScale')
		local Body2 = Humanoid:FindFirstChild('BodyWidthScale')
		local Body3 = Humanoid:FindFirstChild('BodyHeightScale')
		local Head = Humanoid:FindFirstChild('HeadScale')
			 
        Body1.Value = Body1.Value + .03
	    Body2.Value = Body2.Value + .025		
        Body3.Value = Body3.Value + .02
        Head.Value = Head.Value + .015

        Humanoid.WalkSpeed = Humanoid.WalkSpeed - 0.01
        Humanoid.JumpPower = Humanoid.JumpPower - 0.031
  
        script.Parent.Transparency = 1

	    local Sound = script.EatSound
	    Sound.Parent = Player
	    Player:WaitForChild('EatSound')	
	    Sound:Play()
	    wait(Sound.TimeLength)
	    Sound:Destroy()
             if Player.EatSound ~= nil then
	    wait(Player.EatSound.TimeLength)
	    Player.EatSound:Destroy()
           end  
      
script.Parent:Destroy()
 end 
end)
wait(10)
script.Parent:Destroy()

3 comments

0

so you want a sound to play locally?

0

If you want the sound to play separately for each client, use Sound:Play() in a Local Script (where Sound is the Audio).

1

or just put it in the players "PlayerGui"

1 answer

✓ Accepted answer

This is easy to do. I'm assuming by "local" you mean a sound plays only available to the player.

Here's how I would do it.

Before the script.Parent:Destroy(), put this code:

local player = game.Players:GetPlayerFromCharacter(Plr.Parent) -- get player
local sound = Instance.new("Sound") -- make sound
sound.SoundId = "" -- put the ID of your sound here
sound.Parent = player -- put sound in player
repeat wait() until sound.Loaded == true -- wait until it is loaded
sound:Play() -- play the sound
wait(sound.TimeLength) -- wait the sound time duration
sound:Destroy()

Hope this helps!

If it works, accepting my answer is greatly appreciated. :)

2 comments

0

Thanks, I will be trying it right now.

0

Thank you!, I have managed to change it to my own needs and will be posting the finished script shortly, to help any scripter that finds himself with a similar problem.

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