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

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

Asked by 3 years ago

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?

0
idk u need to do in the sametime luxkatana 61 — 3y

3 answers

Log in to vote
0
Answered by 3 years ago

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)

0
can you be more specific? this is really confusing OreyTheOre 52 — 3y
0
It will work when player step on it, OreyTheOre want it to only work when players walk, The_Saver31 260 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
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)
0
But even an part touches it, it makes noise. And the sound doesn't stop when i stop walking OreyTheOre 52 — 3y
0
then look up a humanoid touch script tutorial, we are not your slaves surviarlTheJefkillre 55 — 3y
Log in to vote
0
Answered by 3 years ago

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)

Answer this question