Here is where my issue appears.
I am trying to use a RemoteEvent going from server to client. My main problem is for FireClient() you need to have an argument that is a player. Here is my attempt at this.
--[[
I am trying to get the player who is currently sitting in a seat
The name of my RemoteEvent is "drumEvent"
This is a server script within the seat
]]--
local seat = script.Parent
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local playerInSeat = seat.Occupant.Parent
print(playerInSeat)
local player = game.Players:FindFirstChild(playerInSeat)
print(player)
game.ReplicatedStorage.drumEvent:FireClient(player)
print("Pinging to client")
end)
Now the problem is trying to collect the user from this way fails as local playerInSeat = seat.Occupant.Parent collects it as an “instance” instead of a string. I am not really sure where to go from here and what I should be doing instead!
I could also very possibly be misunderstanding how to use FireClient and be doing this all completely incorrectly
I’m not sure if this is important but this is the client script that will be receiving
The problem your code has is that local player = game.Players:FindFirstChild(playerInSeat) tries to find the Humanoids Parent which is the character inside of game.Players.
Got this one too in the last question..
This is the a bit tricky part I was talking about. The first parameter passed will always turn out to be the player. The rule to keep in mind is that first parameter client or server.
No, you asked here the other way around, so here is that..
remote:FireClient(player, code, stuff) player is always first.
remote:FireClient(code, player, stuff) this would make code be the player.
I actually tried to avoid this in my last script, in the other thread.
The main issue is that FireClient expects a Player object, but seat.Occupant is a Humanoid. You were trying to use seat.Occupant.Parent and then FindFirstChild on that, but that doesn’t give you the player, it gives you the character model.
What I recommend doing is this:
When you have a Humanoid (seat.Occupant), you can get its character model via .Parent.
Then, you can find the Player associated with that character using Players:GetPlayerFromCharacter(character).
local Players = game:GetService(“Players”)
local seat = script.Parent
like this:
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
local humanoid = seat.Occupant
if humanoid then
local character = humanoid.Parent
local player = Players:GetPlayerFromCharacter(character)
if player then
game.ReplicatedStorage.drumEvent:FireClient(player)
print("Pinging to client")
end
end
end)