Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Kick player out of seat?

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.