Problem with players sit as soon as they join (multiple seat)

So i’m trying to make a script that will put player who joined the game to a random seat, and they can’t jump/ get out the seat.
here is the example of 2 seats that i made:

local Players = game:GetService("Players")

local S1 = script.Parent.Sit1
local S2 = script.Parent.Sit2
local check1 = false
local check2 = false

function setseat(player)  -- check when player join the game

	local character = player.Character or player.CharacterAdded:Wait()
	local hm = character:FindFirstChildOfClass("Humanoid")
	character.Humanoid.JumpPower = 0
	if hm then
		if check1 == false then
			wait(1)
			S1:sit(hm)
			check1 = true
		else
			if check2 == false then
			wait(1)
			S2:sit(hm)
			check2 = true	
			end
		end
	end
end

Players.PlayerAdded:Connect(setseat)

Players.PlayerRemoving:Connect(function() -- reset the seat for other player to join

	S1:GetPropertyChangedSignal("Occupant"):Connect(function()
		if S1.Occupant == nil then
			check1 = false
			end
			end)
	S2:GetPropertyChangedSignal("Occupant"):Connect(function()
		if S2.Occupant == nil then
			check2 = false	
			end
		end)
end)

but when i tried to run the game, sometime it’s work ( 2 player with 2 different seat), but sometime it doesn’t (1 player sit, and the other not), and i’m not sure how to fix, can someone please help me, i would really appreciate your help (sorry if you can’t understand what i try to say, i’m not really good at english)
thanks for reading.

Please move this topic to #help-and-feedback:scripting-support

Also I have answered this in a previous topic:

1 Like

Thank you so much, this work perfectly fine, but i’m still kinda confusing about the part that left behind when the player leave the game, is there a way to remove it? (sorry i’m not really good at scripting)

Remove the code related to clone from your code, and instead pass the Seat to ForceSeat.

ok thank you, i figured it out, but i’m not sure if this is a problem, sometime the sitting animation doesn’t work/play

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.