-
What do you want to achieve?
Only the “owner” of the car can sit down in the driver seat
-
What is the issue?
Currently anyone can sit in the seat despite the player’s name being defined in the value “Owner” when being spawned in (different script). The value is 100% being defined however I’m unsure on then why anyone can sit down in the driving seat. I need the player to be jumped rather then being respawned as they may accidentally sit in the vacant drive seat.
-
What solutions have you tried so far?
- I have had it as if the player is > nothing else jump. This led to everyone jumping out of the seat.
- There are zero relevant console errors
seat = script.Parent
seat.Changed:Connect(function(plr)
if seat.Occupant then
local humanoid = seat.Occupant
if humanoid then
local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
if player.Name == not script.Parent.Parent.Owner.Value then
seat:SetNetworkOwner(player)
seat.Occupant.Jump = true
end
end
end
end)
Any help will be greatly appreciated (I’ve not coded in a while so trying to get back into things) If you need anymore info please lmk.
Try this, you can remove the warns. The only differences I made were some slight changes in the formatting and changed your player.Name == not script.Parent.Parent.Owner.Value to player.Name ~= ownerthing
local PlayerService = game:GetService("Players")
local seat = script.Parent
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
warn("Occupancy Changed")
local occupant = seat.Occupant
if occupant then
warn("Valid Occupant")
local player = PlayerService:GetPlayerFromCharacter(occupant.Parent)
local Owner = script.Parent.Parent.Owner
if player and player.Name ~= Owner.Value then
warn(`Occupant not expected user, got {occupant.Name} expected {Owner.Value}`)
seat.Occupant.Jump = true
end
end
end)
Final Version with Debouncing
local seat = script.Parent
local debounce = false
seat.Changed:Connect(function(property)
if debounce then return end
debounce = true
if property == "Occupant" and seat.Occupant then
local humanoid = seat.Occupant
if humanoid then
local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
if player then
local owner = seat.Parent:FindFirstChild("Owner")
if owner and owner:IsA("StringValue") and player.Name ~= owner.Value then
humanoid.Jump = true
else
-- Optionally, set the network owner to the player
seat:SetNetworkOwner(player)
end
end
end
end
debounce = false
end)
-- Optionally, disconnect the event when the seat is destroyed
seat.AncestryChanged:Connect(function(_, parent)
if not parent then
seat.Changed:DisconnectAll()
end
end)