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

How do you make sound play locally whenever he touches the brick ?

Asked by
Bulvyte 388 Moderation Voter
8 years ago

So i'm actually stuck on this thing where you pass the brick the sound changes like in different games you change biomes the sound changes i wanna do that, but only that the player can hear it not others but how ? Please help me i can't really script that good...

Like here i: http://prntscr.com/876hi6

I've putted the Sound in the Part and the localscript in sound whenever it touches the brick i want the sound to play only for the player. I do know somehow u need to locate the player when he touches it instance a new sound but i don't know how to write it. Please help even i tried with this script:

function onTouch(Part)
    wait(.1)
    script.Parent:Play()
end

script.Parent.Touched:connect(onTouch)

like in this game http://www.roblox.com/games/26582328/BloxScape-Pre-Alpha i've tested i've moved from 1 brick to other brick then it changed sounds. thats how i want the script to be :/ And whenever u touch the brick make sure the sound doesnt play again and again whenevr u touch it. like it works again until the sound ends

1 answer

Log in to vote
0
Answered by
Validark 1580 Snack Break Moderation Voter
8 years ago

For Local things like this, you're going to want to go with a LocalScript inside StarterGui. (Make sure FilteringEnabled is on)

Refer to my example script

-- This script is a localscript inside PlayerGui
function onTouch(PartThatTouched)
    -- Check to see if the part that touched is yourself (because everyone in the server is running this script locally, so you only need to worry about yourself)

    if PartThatTouched.Parent == game.Players.LocalPlayer.Character then

        -- If it was you that touched the part, play a song only you can hear

        local sound = Instance.new('Sound')
        sound.SoundId = "http://www.roblox.com/asset/?id=" .. asset
        sound.Parent = script.Parent
        sound: Play()
    end
end

game.Workspace.Part.Touched:connect(onTouch)

Ad

Answer this question