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

[Solved] Anyone know how to run a sound script using two panels (parts) on a local script?

Asked by 6 years ago
Edited 6 years ago

Alright, so I've been working on making some random scripts in order to better my understanding of lua script so I can use it to make a game. I successfully created a four button door with the knowledge my friend had given me and a little help from the internet when it came to CFrames. Afterwards, I decided to change my focus to other tasks, like this one...

I wanted to create a containment chamber for a block with a weird face. I thought it would be interesting to play a weird song when you entered the room, and so I made a script. At first, the issue was just that, it was a script, not a local script. But I was able to get by just by putting "WackyTune," my sound, in StarterGui. I have two transparent panels, one in front of my door and one behind it. The back panel has CanCollide, while the front does not. When you touch the back panel, the music plays for the localplayer, disables its CanCollide property, and gives the front panel the collision property, which basically does what the back panel does, but in reverse. The great thing is, it works!

The bad thing is, two players walking side by sides could screw up the script, as there is some space between the two panels, and one person could activate the panel (disabling its collision property, and preventing the other from hearing the sound. The solution I thought of was use a local script. That way, the panels collision property would only change on the client-side of the program, remaining unchanged for the rest of the players. The problem is, it doesn't run in the local script.

So my question is... How could I get this code to run in a local script?

script.Parent.SoundPlay.Touched:Connect(function(Play)
    if Play.Parent:FindFirstChild('Humanoid') then
        game.Players[Play.Parent.Name].PlayerGui.WackyTune.Playing = true
        script.Parent.SoundPlay.CanCollide = false
        script.Parent.SoundStop.CanCollide = true
    end
end)

script.Parent.SoundStop.Touched:Connect(function(Stop)
    if Stop.Parent:FindFirstChild('Humanoid') then
        game.Players[Stop.Parent.Name].PlayerGui.WackyTune.Playing = false
        script.Parent.SoundPlay.CanCollide = true
        script.Parent.SoundStop.CanCollide = false
    end
end)
0
Place it in PlayerGui and script.Parent.SoundPlay will be like workspace.SoundPlay or wherever the SoundPlay object is User#19524 175 — 6y
0
Succes! Thank you very much! ZeroNoey 19 — 6y

Answer this question