Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Kick player out of seat?

Asked by 4 years ago

I made some code to find the name of a person that sits in the car seat. It puts the name as a string value. Is it possible to find if a player sits in the seat to kick him out of the seat if his name isn't the string values name?

local seat = script.Parent
local owner = script.Parent.Owner
local Players = game:GetService("Players")

seat:GetPropertyChangedSignal('Occupant'):Connect(function()
  if (seat.Occupant) then
    local player = game.Players:GetPlayerFromCharacter(seat.Occupant.Parent)
    if (not player or not player:FindFirstChild('PlayerGui')) then return; 
end

    LockGUI = player.PlayerGui:WaitForChild("LockGui").StarterRaftLock
    local locked = LockGUI.Locked
    owner.Value = seat.Occupant.Parent.Name
    if not LockGUI.Visible then
      LockGUI.Visible = true
        end
    end
end)

seat:GetPropertyChangedSignal('Occupant'):Connect(function()
    if not (seat.Occupant) then
        LockGUI.Visible = false
    end
end)

1 answer

Log in to vote
0
Answered by 4 years ago

You could check if a seatWeld is a child of the seat and then check the C1 value of the Seatweld, this is the players HumanoidRootPart then check if the players name isnt the the string value if so destroy the seatweld like this:

seat:GetPropertyChangedSignal('Occupant'):Connect(function()
    for i,child in pairs(seat:GetChildren) do
        if child.Name == "SeatWeld" then
            if child.C1.Parent.Name == "Name you want to kick out" then
                child:Destroy()
            ned
        end
    end
end)
Ad

Answer this question