-
What do you want to achieve? So I have this song player here and I want it to play sound from the seat (already added sound to seat) and show player the song info
-
What is the issue? Right now the song is able to play and I can hear it properly, but the song info on PlayerGui won’t change
-
What solutions have you tried so far? I looked at how to detect player in Devforum already but I don’t think it quite worked
Just take a look at the script below, its not a localscript, just a normal script. I think I might have used a function wrong but I’m not sure where
The script is put inside sound that is inside the seat
The reason why its a script instead of a local script is because for some reason putting a localscript won’t play the music
The reason why its in player gui instead of starter gui is because the radio gui is in the seat and will be cloned to player gui once the player is sitting on it and delete once the player left
local sound1 = "10199337266" -- Sound IDs
local sound2 = "5409360995"
local music = script.Parent
local seat = script.Parent.Parent
while true do -- Loop
wait()
music.SoundId = "rbxassetid://"..sound1 -- making the sound ID the first song
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local hum = seat.Occupant
if not hum then return end
local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
local Songname = plr.PlayerGui.radio.radiopannel.SongName
Songname.Text = "Madeon - Love You Back"
end)
music:Play() -- playing the first song
music.Ended: wait(1) -- when the song ends
music.SoundId = "rbxassetid://"..sound2 -- changes the sound ID to the second song
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local hum = seat.Occupant
if not hum then return end
local plr = game.Players:GetPlayerFromCharacter(hum.Parent)
local Songname = plr.PlayerGui.radio.radiopannel.SongName
Songname.Text = "Dion Timmer - Shiawase"
end)
music:Play() -- plays the second song
music.Ended: wait()
end
2 Likes
You can get the player that is sitting on a seat by using Seat.Occupant
1 Like
I tried that already, it shows seat.Occupant is a humanoid
When I tried to go for
local human = Seat.Occupant
local player = human.Parent.Name
When doing tests, the console tells me that human.Parent.Name is a nil index
For this script I have to get the player’s name
So that I can use
game.Players:FindFirstChild (player.Name).PlayerGui.The path to the textlabel that shows song info
1 Like
Oh, right. I forgot it’s the humanoid.
You don’t need to use .Name, just do Seat.Occupant.Parent
1 Like
Were you sitting on the seat when it fired?
yes, I didn’t use any remote event, so by “fired” do you mean I need a remote event of some sort?
I should add, to avoid errors you could do:
if Seat.Occupant ~= nil then
-- your code here
end
1 Like
Oops, I just mean when that part of the code ran
1 Like
Still didn’t work for some reason, the console still says “parent” is a nil index for some reason
1 Like
Is there any chance you could send an image of your explorer?
1 Like
Ok so my game already has a complicated functioning system that I need to explain to you or else you might get confused.
So the cars are kept in server storage, I have a spawnning script which I can clone one of them and change its name to (player name here)scar (e.g Midnight_Hurricanescar)
Also what I want to achieve is to let the Music keep playing in the car with no volume when player didnt open the radio and just increase the volume when the player clicks on the radio button, so that the player thinks it as started playing radio.
1 Like
Is your script a localscript or a serverscript?
1 Like
a normal script? I guess, its definatly not local script, for some reason, although using the same code, in local script it wouldn’t even play the music
1 Like
Which one? the script for the music in the car or the car spawnning script?
1 Like
Are you wanting to play the music locally or for everyone?
1 Like
For everyone, and as well as it being muffled for everyone outside the car, only the people inside the car can hear it normally
1 Like
Try replacing the code you currently have with this:
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local hum = seat.Occupant
if not hum then return end
local plr = hum.Parent
local songName = game.Players[tostring(plr)].PlayerGui.radio.radiopannel.SongName
songName.Text = "Madeon - Love You Back"
end)
1 Like
Ok yes this can work but there is another problem, the text that shows music info still won’t show
I’ve taken a look at console, and it says “PlayerGui.radio is not a child of Midnight_Hurricane”
So I figured out whats problem, because the radio gui is currently inside the car, and only at the moment the player sit in the driver seat, will it clone to playergui, so now we need the script to:
repeat wait() until PlayerGui.radio.radiopannel.SongName ~= nil
right?
(just sending this to make sure that I’m using the right way, I’m very new to scripting)
1 Like
Yes, that should work.
ㅤㅤㅤㅤㅤㅤㅤㅤㅤ
1 Like