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

How do you make a teleporter work ONLY when there is at least 5 people who touch it at once?

Asked by 4 years ago
Edited 4 years ago

Here is a script for a teleporter that I made:

local Teleport = workspace.TeleportPad

function Touch(hit)

if script.Parent.Locked == false and script.Parent.Parent:FindFirstChild("TeleportPad").Locked == false then script.Parent.Locked = time script.Parent.Parent:FindFirstChild("TeleportPad").Locked = true

local pos = script.Parent.Parent:FindFirstChild("TeleportPad")

hit.Parent:moveTo(workspace.TeleportPoint.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:FindFirstChild("TeleportPad").Locked = false end end

script.Parent.Touched:Connect(Touch)

I want the teleporter to only work when at least 5 people (including both players and NPCs) step on it. What do I need to add to the script in order for that to happen?

0
Please F o r m a t the script Nguyenlegiahung 1091 — 4y
0
yep TheRealPotatoChips 793 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

you can make a table when a person touches it like this

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then -- if there is a humanoid, its a player/character
        local plrs = {}
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        table.insert(plrs,player)
        if #plrs >= 5 then
            for _,v in pairs(plrs) do
                game:GetService("TeleportService"):Teleport(yourplaceidhere,v)
            end
        end
    end
end)

`

0
That would reset the table every time someone touches it. Make the table outside the function Spjureeedd 385 — 4y
0
And this wouldn't work. NPCs have Humanoids but they are not players. So this would error when trying to get the player instance from the character that touched Spjureeedd 385 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Hello there!

So to do this script, this is how I would do it.


local part= script.Parent local folderOfPlayers= part.Folder local amountofplayers= 0 local teleportPlace= 4918710826 --put your place id here local teleportService= game:GetService("TeleportService") part.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player= game.Players:GetPlayerFromCharacter(hit.Parent) if player then local playerName= hit.Parent.Name local findValue= folderOfPlayers:FindFirstChild(playerName) if not findValue then local value= Instance.new("StringValue") value.Name= playerName value.Parent=folderOfPlayers amountofplayers= amountofplayers + 1 if amountofplayers== 5 then for i,v in pairs(game.Players:GetChildren()) do local findPlayer= v.Name if folderOfPlayers:FindFirstChild(findPlayer) then teleportService:Teleport(teleportPlace, player) end end end end end end end)

This is quite a bit of code, so please, if this worked for you, tell me. If not, show me what error occurs.

0
Also another note here, I may not be the most efficient at code out there, but I find tables harder to work with because Roblox Lua doesn't have many options with it compared to other languages like Python.pro Cyroxite 46 — 4y
Log in to vote
0
Answered by 4 years ago

Use a table and count how many players are touching the teleporter, once the minimum is reached, teleport them

Use this:

local Teleport = workspace.TeleportPad

local teleportService = game:GetService("TeleportService")
local playerAmount = {}
local placeId = 1234567890
local minPlayers = 5

function Touch(hit)
    if hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)

            if #playerAmount >= minPlayers then
            for i, v in pairs(playerAmount) do
                        teleportService:Teleport(placeId, v)

                table.remove(playerAmount, i)
            end
        end
    end
end)

script.Parent.Touched:Connect(Touch)

Answer this question