Hello, I want to achieve a script able to change the music when you get through the part for the player only, not everyone on the same server.
I’m asking for your help because when I turn the normal script into a local script, nothing works. My scripter friends can help neither.
I put a normal script in the same part to compare if the script works or not.
Local scripts doesn’t run inside a part and maybe try to replace :Pause() with :Stop()
Do you have a solution to correct without using a part?
Script:
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
workspace.SPA:Play()
workspace.TheSecretForest:Stop()
end
end)
Oh wait you want to change it only for the player that touched the part, my bad
- Add RemoteEvent in the ReplicatedStorage.
- Add a script inside the part
- Add a script inside the StarterGui
Script:
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
Event:FireClient(player)
end
end)
Local Script:
local Event = game.ReplicatedStorage:WaitForChild("RemoteEvent")
Event.OnClientEvent:Connect(function()
workspace.SPA:Play()
workspace.TheSecretForest:Stop()
end)
Is the Local Script inside the StarterGui?
yes you can place it in other places that local scripts can run in it but i like in starter gui
That’s very helpful thank you and I know I’m bad at scripting but if I need to do it again with another part, can I just rename the Remote Event?
Yes but you will have to change it in the script
It’s ok I was a bad scripter too but along the time…
I did a first test and it’s not perfect yet. I think RemoteEvent worked but the music disappeared. No music plays. I don’t have any error in the output sadly.
Can you send me an image of the Explorer
In the first screenshot, you can see the invisible part which has the script using the RemoveEvent. You need to get through yes.
In the second screenshot, you can see the script inside the part of the first screenshot.
In the 3rd screenshot, there is the localscript used by the RemoteEvent.
wait ill test it my self and ill be right back
LocalScripts do not run in most services, including the Workspace. StarterGui is also not meant for LocalScripts in general, so I suggest keeping them in StarterPlayerScripts or StarterCharacterScripts.
Also, since this LocalScript is just for music, you shouldn’t waste resources and performance by doing the .Touched event on the server and firing a RemoteEvent as you are discussing at the moment.
LocalScript in StarterPlayerScripts: (I made it so that it only works once, if you don’t want this, please tell me)
local _workspace = game:GetService("Workspace")
local players = game:GetService("Players")
while not _workspace:FindFirstChild("ChangeMoiCette musiqueSPA") do wait() end
local con = nil
con = _workspace["ChangeMoiCette musiqueSPA"].Touched:Connect(function(hit)
if not hit.Parent then return end
if not hit.Parent:FindFirstChildWhichIsA("Humanoid") then return end
if hit.Parent.Name ~= players.LocalPlayer.Name then return end
_workspace.SPA:Play()
_workspace.TheSecretForest:Pause()
con:Disconnect() -- So that it only runs once.
end)
For me it worked perfectly fine.
Very interesting script, in fact, the player can cross between 2 different parts. So the script needs to be reusable. There is a part in front of the spa to enter, another part which is outside for when you leave the building.
I see, then this is the re-usable version:
local _workspace = game:GetService("Workspace")
local players = game:GetService("Players")
while not _workspace:FindFirstChild("ChangeMoiCette musiqueSPA") do wait() end
_workspace["ChangeMoiCette musiqueSPA"].Touched:Connect(function(hit)
if not hit.Parent then return end
if not hit.Parent:FindFirstChildWhichIsA("Humanoid") then return end
if hit.Parent.Name ~= players.LocalPlayer.Name then return end
if _workspace.SPA.Playing == true then return end
_workspace.SPA:Play()
_workspace.TheSecretForest:Pause()
end)
Really? Maybe my audios were set up very differently. My first TheSecretForest is on playing by default, while the other one is off by default



