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

Teleport script for specific players not working properly?

Asked by 3 years ago

Hey there! Very amateur scripter who knows basic stuff and mainly uses youtube tutorials to make scripts! I'm having a bit of trouble getting this one to work. It doesn't properly run despite not having any noticeable flaws in ROBLOX studio, can anybody help me out with this?

local placeID_1 = 6305834065
local TeleportService = game:GetService("TeleportService")
local Owner = "FrigidusIncendium, Strawberrymlqq"

        local function onPartTouch(otherPart)
            script.Parent.Touched:Connect(onPartTouch)
    local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
    if player == Owner then
        TeleportService:Teleport(placeID_1, player)
            end
        end

Thanks!

0
What is it supposed to do? pugguy1000 3 — 3y
0
Script is supposed to detect whether or not either of the two players are touching the brick, then teleport them to another game FrigidusIncendium 24 — 3y
0
Bit of a PSA but please indent your code so we can read it properly <3 thecelestialcube 123 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

You should use a table instead of a string, if you don't know what a table is, it's something you can store many different values inside such as strings, booleans, numbers, etc. If you store your name (or others) inside the table you can then use table.find() whenever a player touches the part to check if their name is inside the table, if it doesn't find their name inside the table then it'll return nil, otherwise, if it does find their name in the table then it'll return the index position of it.

local placeID_1 = 6305834065
local TeleportService = game:GetService("TeleportService")
local Owner = {"FrigidusIncendium", "Strawberrymlqq"}

local function onPartTouch(otherPart)

    local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)

    if player then 
        if table.find(Owner, player.Name) then
            TeleportService:Teleport(placeID_1, player)
        end
    end
end

script.Parent.Touched:Connect(onPartTouch)
0
This works perfectly and taught me something new! Thank you very much! FrigidusIncendium 24 — 3y
0
No problem. Make sure to mark this as the answer to your question. xInfinityBear 1777 — 3y
0
I'm sorry, but I'm having a little bit of trouble figuring out how. Is it cool if I get a quick explanation, I wanna mark this as answered FrigidusIncendium 24 — 3y
0
There should be a button somewhere around my answer that you can click to accept this as the answer to your question. xInfinityBear 1777 — 3y
0
Thank you very much again! Take care! FrigidusIncendium 24 — 3y
Ad

Answer this question