Hi
I am trying to check if the player is in or out of the seat. But for some reason it doesn’t work.
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
-- plr seated
else
-- plr unseated
end
end)
Hi
I am trying to check if the player is in or out of the seat. But for some reason it doesn’t work.
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
-- plr seated
else
-- plr unseated
end
end)
Your code seems to all be right. Could you show us your entire script?
Also, keep in mind that GetPropertyChangedSignal will only fire when someone sits down or gets up. It will not fire at any other times.
I just tested the following code and it works as expected. Sounds like your problem lies in some other code.
local seat = script.Parent
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
print(seat.Occupant and seat.Occupant:GetFullName())
end)
Yes, I will send it in a minute. Btw this code worked fine but it’s now that I realised it isn’t working properly and I made many different changes but can’t find out what causes the issue.
Whole script:
-- info --
local proximityPrompt = script.Parent
local seat = script.Parent.Parent
local car = seat.Parent
-- events --
local lockpickEvent = game.ReplicatedStorage.RemoteEvents.Car.openLockpickingGui
local lockpickFinished = game.ReplicatedStorage.RemoteEvents.Car.lockpickFinished
local lockpickFailed = game.ReplicatedStorage.RemoteEvents.Car.lockpickFailed
local plrSeatedEvent = game.ReplicatedStorage.RemoteEvents.Car.plrSeated
-- functions --
local function deleteHeldItem(plr, lockpickType)
for i,v in ipairs(plr.Character:GetChildren()) do
if v:IsA("Tool") and v.Name == lockpickType then
v:Destroy()
end
end
end
-- code --
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
proximityPrompt.Enabled = false
plrSeatedEvent:FireClient(game.Players:FindFirstChild(seat.Occupant.Parent.Name))
else
proximityPrompt.Enabled = true
end
end)
proximityPrompt.Triggered:Connect(function(player)
if player == car.Owner.Value then
seat:Sit(player.Character.Humanoid)
elseif car.unlocked.Value == true then
seat:Sit(player.Character.Humanoid)
else
local itemEquipped
for i,item in pairs(player.Character:GetChildren()) do
if item:IsA("Tool") then
itemEquipped = item
break
end
end
if itemEquipped and itemEquipped.Name == "Lockpick" then
local lockType = seat.Parent.lockType
lockpickEvent:FireClient(player, lockType.Value, car, itemEquipped.Name)
else
-- lockpick not equipped
end
end
end)
lockpickFailed.OnServerEvent:Connect(function(player, vehicle, lockpickType)
deleteHeldItem(player, lockpickType)
end)
lockpickFinished.OnServerEvent:Connect(function(player, vehicle)
if vehicle and car == vehicle then
seat:Sit(player.Character.Humanoid)
vehicle.unlocked.Value = true
end
end)
also explorer: (underlined script is the one I send the code of)
Hmm. This looks like it should still work. Can you send a video of the code in action?
Yea I can do that tomorrow, I don’t really get how it would help since nothing prints it just puts me in the seat and while testing I put a print if the get property change works and it does and I printed seat.Occupant and it gave me humanoid allthough the if statment doesn’t work.
plrSeatedEvent:FireClient(game:GetService("Players"):GetPlayerFromCharacter(seat.Occupant.Parent))
Might be worth adding waits on those RemoteEvent instances.
Thanks, I will try it out after school.
Oh haha I just realised what is this for. This event is only here because it didn’t work on a local script (this part: seat:GetPropertyChangedSignal(“Occupant”):Connect(function()) so I made an event for it but now I know it just doesn’t work for some reason.
Oh my god I am so sorry. It turned out the seat property “Disabled” was ticked.
LOL it’s alright we all have those moments. Glad everything is working fine now. Good luck on the rest of the project!