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

I need help with a teleportation script thing!?

Asked by 8 years ago
Edited 8 years ago

I want to make it so when a player touches a certain part they can type for example: teleport 1 and the would be teleported to another place in my universe, here is the error I am getting: Workspace.Model.TeleportPad.Script:8: attempt to index field 'Chatted' (a nil value)

Here is my script so far:

local TeleportService = game:GetService("TeleportService")
local floor1Id = 518904899
local floor2Id = 518905949

script.Parent.Touched:connect(function(hit)
    if hit.Parent:findFirstChild("Humanoid") then
        local player = hit.Parent:findFirstChild("Humanoid").Parent.Name
        player.Chatted:connect(function(msg)
            if msg:sub(1,8) == "teleport" then
                if msg:sub(10) == 1 then
                    TeleportService:Teleport(floor1Id, player)
                elseif msg:sub(10) == 2 then
                    TeleportService:Teleport(floor2Id, player)
                end
            end
        end)
    end
end)
0
can you please put this in a code block. User#5423 17 — 8y
0
Yeah KuroNakamura 5 — 8y

1 answer

Log in to vote
0
Answered by
soved 69
8 years ago
Edited 8 years ago

You wrote this? Looks like a Free Model Script to me, but OK.

local player = hit.Parent:findFirstChild("Humanoid").Parent.Name -- Are you serious?

HERE IS HOW IT SHOULD BE DONE

-- ServerScript.

local PLAYERS = game:GetService("Players")
local TS = game:GetService("TeleportService")
local Part = script.Parent
local ID_1 = 518904899
local ID_2 = 518905949
local Table = {}

PLAYERS.PlayerRemoving:connect(function(Plr)
    if Table[Plr.UserId] then
        Table[Plr.UserId] = nil -- Remove the Debounce.
    end
end)

Part.Touched:connect(function(Hit)
    local Plr = PLAYERS:GetPlayerFromCharacter(Hit.Parent)

    if Plr then
        if not Table[Plr.UserId] then -- Could also do only Plr, but I prefer using the UserId.
            Table[Plr.UserId] = true

            Plr.Chatted:connect(function(Msg)
                -- The rest you can of course fill in yourself!!!
            end)
        end
    end
end)

I wrote this pretty quickly, so contact me if I made an error.

Ad

Answer this question