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

How to make if three people sit on a sofa, it teliports them?

Hello, I'm a beginner scripter and I'm stuck on making this sofa.

local Seat1 = game.Workspace.Seat1

local Seat2 = game.Workspace.Seat2

local Seat3 = game.Workspace.Seat3

Seat1 and Seat2 and Seat3.Touched:Connect(function(hit)

if hit and hit.Parent:FindFirstChild("HumanoidRootPart") then

	hit.Parent.HumanoidRootPart.CFrame = CFrame.new(0, 0.5, -14)

end

end)

1 comment

0

Seat1 and Seat2 and Seat3.Touched:Connect(function(hit) would probably only activate if all 3 were touched at the same time.

2 answers

✓ Accepted answer
local Seat1 = workspace.Seat1
local Seat2 = workspace.Seat2
local Seat3 = workspace.Seat3
local playersSeated do
	playersSeated=Instance.new("BindableEvent",script)
	local players,debounce={},false
	local function update(v,add)
		local char=v.Part1.Parent
		if add then
			players[#players+1]=char
		else
			table.remove(players,table.find(players,char))
		end
		if #players==3 and not debounce then
			debounce=true
			local players=table.clone(players)
			for i,char in ipairs(players)do
				if i==#players then
					debounce=false
				end
				local hum=char:FindFirstChildOfClass"Humanoid"
				if not hum then continue end
				hum.Jump=false
				wait()
				hum.Jump=true
				wait(.1)
				local msg,v=pcall(playersSeated.Fire,playersSeated,hum)
				if not v then
					warn(msg)
				end
			end
		end
		
	end
	for _,v in ipairs{Seat1,Seat2,Seat3}do
		v.Anchored=true
		v.ChildAdded:Connect(function(v)update(v,true)end)
		v.ChildRemoved:Connect(update)
	end
end;



playersSeated.Event:Connect(function(hit)
	
		if hit and hit.Parent:FindFirstChild("HumanoidRootPart") then
			 
			    hit.Parent.HumanoidRootPart.CFrame = CFrame.new(0, 0.5, -14)
			 
			end
end)

There is a property inside of a 'Seat' that is called 'Occupied' basically use if statements to check if the property is 'occupied' == true then you can copy a bit of code from TeleportService YT Videos :)

1 comment

0

Sorry, but what am I supposed to do?

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