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

How do i make a sound play when a player walks on a SPECIFIC part?

Hey there, i'm trying to make a slime but i have no scripting knowledge so i came here to get help.

How do i make a sound occur while a player walks onto a specific part? I want the sound to loop, but when the character stops walking i want the sound to stop. How do i do it?

1 comment

0

idk u need to do in the sametime

3 answers

u basically need first a function look `` local function sound() game.soundservice.oof.playing = true

end

game.workspace.part.touched:connect(function name)

game.workspace.part.touched:connect(sound)

2 comments

0

can you be more specific? this is really confusing

0

It will work when player step on it, OreyTheOre want it to only work when players walk,

local music = path to music here
game.Workspace. put your part's name here .Touched:Connect(function()
music.Playing = true
music.Looped = true
end
game.Workspace.part name here.TouchEnded:Connect(function()
music.Playing = false
music.Looped = false
end)

2 comments

0

But even an part touches it, it makes noise. And the sound doesn't stop when i stop walking

0

then look up a humanoid touch script tutorial, we are not your slaves

This will only play the sound if they are actively walking, and is scripted as if it were inside the part.

local sound = script.Parent:WaitForChild("Sound")
sound.Looped = true

local deb = false

script.Parent.Touched:Connect(function(hit) -- detect touch
	if deb == false then
		deb = true
		local hum = hit.Parent:FindFirstChild("Humanoid") -- get needed parts and make sure this is a player
		local plr = game.Players:GetPlayerFromCharacter(hit)
		if hum and plr then
			if hum.MoveDirection.Magnitude > 0 then -- if they are walking
				sound:Play()
				repeat wait() until hum.MoveDirection.Magnitude == 0 -- stop the script until they stop walking
				sound:Stop()
			end
		end
		deb = false
	end
end)

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