He’s talking about that local scripts can only run in certain locations:
So I need to make the run context client on the current server script, or do I need to make a new server script, make the run context client, and paste the old local script into it?
Make a new server script, make the run context client, copy paste the old local script’s code into it and then place your new script where your old localscript was
Thanks, I’m now getting the error “Argument 1 Missing or Nil” on the firing of the remote events. (I’m really sorry if this is getting annoying I do appreciate the help a lot)
GetPropertyChangedSignal doesn’t pass any values. You need to find who the player is by checking who the occupant is and finding the corresponding player.
You’ll then want to save this to a variable as when the player exits the seat the occupant will no longer exist, so you’ll want to remember who was just seated.
You can find the character’s player by doing game.Players:GetPlayerFromCharacter(seat.Occupant.Parent).
Demonstration:
https://gyazo.com/486b208f68d7eb03957dfeb92dce516a
LocalScript inside of StarterPlayerService, Code:
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
local seat = game.Workspace.Seat
seat.Changed:Connect(function(property)
local occupant = seat.Occupant
if property ~= "Occupant" then
return
end
if occupant then
local character = occupant.Parent
local humanoid = character.Humanoid
local player = players:GetPlayerFromCharacter(character)
if player then
print(player.Name.." seated")
seat.ProximityPrompt.Enabled = false
end
else
print("no longer seated")
seat.ProximityPrompt.Enabled = true
end
end)
Works perfectly fine for me, and didn’t have to use a remote
event like the other guy has been telling you to do…
If this worked, then mark it as the solution.
Again, he’s doing things on the client.
The seat isn’t just a seat its a car seat so I’d have to find that through I,v in pairs or finding the parents of a part passed through the remote event.
I’m to tired for this lol I am sure I am doing something INCREDIBLY stupid
server
local Seat = script.Parent.Parent
local ProximityPrompt = script.Parent
local Ownership = ProximityPrompt.Ownership
local Locked = ProximityPrompt.Locked
local LockedPrompt = script.Parent.LockPart.ProximityPrompt
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
game.Players:GetPlayerFromCharacter(Seat.Occupant)
if Seat.Occupant then
ProximityPrompt.Enabled = false
LockedPrompt.Enabled = false
game.ReplicatedStorage.HideCarPrompts:FireClient(Seat.Occupant)
else
ProximityPrompt.Enabled = true
LockedPrompt.Enabled = true
game.ReplicatedStorage.ShowCarPrompts:FireClient(Seat.Occupant)
end
end)
ProximityPrompt.Triggered:Connect(function(Player)
if Ownership.Value == "" and Locked.Value == false then
Ownership.Value = Player.Name
Seat:Sit(Player.Character.Humanoid)
elseif Ownership.Value ~= Player.Name and Locked.Value == false then
Seat:Sit(Player.Character.Humanoid)
elseif Ownership.Value == Player.Name and Locked.Value == false then
Seat:Sit(Player.Character.Humanoid)
elseif Ownership.Value ~= Player.Name and Locked.Value == true then
end
end)
ServerScript but with client run context:
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Seat = script.Parent
game.ReplicatedStorage.HideCarPrompts.OnClientEvent:Connect(function()
if Seat.Occupant == Player.Character.Humanoid then
print("Player in Seat")
script.Parent.Parent.Body.FrontLeft.ProximityPrompt.Enabled = false
script.Parent.Parent.Body.Left.ProximityPrompt.Enabled = false
script.Parent.Parent.Body.Right.ProximityPrompt.Enabled = false
end
end)
game.ReplicatedStorage.CarPrompts.OnClientEvent:Connect(function()
print("Player in Seat")
script.Parent.Parent.Body.FrontLeft.ProximityPrompt.Enabled = false
script.Parent.Parent.Body.Left.ProximityPrompt.Enabled = false
script.Parent.Parent.Body.Right.ProximityPrompt.Enabled = false
end)
Again, I know like you’ve already said.
I did mine on the client and it work, like shown in the gyazo GIF.
Seat.Occupant.Parent, I thought seat.Occupant was the character but it was the humanoid.
He’s clearly being seated on the server. That would not be getting replicated to the client. .Changed is functionally identical to getpropertychangedsignal.
Thats not mine point, I wans’t talking about property/change events
yeah so you’d compare it to player.character.humanoid?
Why not type the code for him if mine ins’t the solution.
You also keep explaining several times but he keeps getting stuck,
if you did actions instead of explaining then it would probably be more beneficial to him, so that he can understand you better.
I give up with this topic, bye.
No, you’d run game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent) and it would return the player. You’d then use this to fire the remote.
local Seat = script.Parent.Parent
local ProximityPrompt = script.Parent
local Ownership = ProximityPrompt.Ownership
local Locked = ProximityPrompt.Locked
local LockedPrompt = script.Parent.LockPart.ProximityPrompt
local previousPlayer
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat.Occupant then
ProximityPrompt.Enabled = false
LockedPrompt.Enabled = false
local player = game.Players:GetPlayerFromCharacter(Seat.Occupant)
previousPlayer = player
game.ReplicatedStorage.HideCarPrompts:FireClient(player)
elseif previousPlayer then
ProximityPrompt.Enabled = true
LockedPrompt.Enabled = true
game.ReplicatedStorage.ShowCarPrompts:FireClient(previousPlayer)
previousPlayer = nil
end
end)
Your solution fundamentally does not work in this person’s case. .Changed is a less effective alternative to :GetPropertyChangedSignal, which he already pointed out, does not work, because the property he’s trying to read on the client is not replicated.
We appreciate the effort you put into trying to help resolve his issue, but please don’t try armchairing people into changing their whole setup if they’re not interested.
I don’t see how you could get the player from that? Also I got the error FireClient: player argument must be a player object
:GetPlayerFromCharacter is a function inside of game.Players. You can view all of them via the developer API, much like the occupant property.
https://create.roblox.com/docs/reference/engine/classes/Players#GetPlayerFromCharacter
Can you show me your code and comment which line gave you the error?
Line 16 and I assume it will also come up on like 20
Server side:
local Seat = script.Parent.Parent
local ProximityPrompt = script.Parent
local Ownership = ProximityPrompt.Ownership
local Locked = ProximityPrompt.Locked
local LockedPrompt = script.Parent.LockPart.ProximityPrompt
local previousPlayer
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat.Occupant then
ProximityPrompt.Enabled = false
LockedPrompt.Enabled = false
local player = game.Players:GetPlayerFromCharacter(Seat.Occupant)
previousPlayer = player
game.ReplicatedStorage.HideCarPrompts:FireClient(player)
elseif previousPlayer then
ProximityPrompt.Enabled = true
LockedPrompt.Enabled = true
game.ReplicatedStorage.ShowCarPrompts:FireClient(previousPlayer)
previousPlayer = nil
end
end)