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

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

Asked by
jjjona1 -1
2 years ago
Edited 2 years ago

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)

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

2 answers

Log in to vote
0
Answered by 2 years ago
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)

Ad
Log in to vote
0
Answered by 2 years ago

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 :)

0
Sorry, but what am I supposed to do? jjjona1 -1 — 2y

Answer this question