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

Game teleport script on chat not working?

Asked by 9 years ago

This script WAS working, until I added the GUI configuring parts to the script. This script is supposed to teleport the player to R2D when they chat "r2d" (With :lower()) This script is a regular script in a GUI:

game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(msg)
        msg = msg:lower()
        if msg == "r2d" then
            script.Parent.TpName.Visible = true
            script.Parent.TpTo.Visible = true
            script.Parent.Frame.BackgroundTransparency = 0.8
            wait(1)
            script.Parent.Frame.BackgroundTransparency = 0.6
            wait(1)
            script.Parent.Frame.BackgroundTransparency = 0.4
            wait(1)
            script.Parent.Frame.BackgroundTransparency = 0.2
            wait(1)
            script.Parent.Frame.BackgroundTransparency = 0
            wait(2)
            game:GetService("TeleportService"):Teleport(147513144,plr) -- I didn't put the real R2D ID here. It's just a random ID to test this.

        end
    end)
end)
0
First you can't test the Place when you're on Studio. woodengop 1134 — 9y
0
Are you waiting 6 seconds after you chat? YellowoTide 1992 — 9y
0
^^they both make a point BSIncorporated 640 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

Your script never checked against players that joined before the script started. Also, it's checking against all players even though it's only meant to check against one.

Here's my solution:

A script in workspace or ServerScriptService:

local Players=game:GetService("Players")
local TeleportService=game:GetService("TeleportService")
local GameID=163612261

function OnPlayerAdded(Player)
    -- add events to players
    local Event=Player:FindFirstChild("OnPlayerTeleporting")
    if not Event then
        Event=Instance.new("RemoteEvent",Player)
        Event.Name="OnPlayerTeleporting"
    end

    -- chat hook
    Player.Chatted:connect(function(Message)
        if Message:lower()=="r2d" then
            wait(1)
            TeleportService:Teleport(GameID,Player)
        end
    end)

end

Players.PlayerAdded:connect(OnPlayerAdded)

-- handle players connected before the script loaded
for i,v in pairs(Players:GetPlayers()) do
    OnPlayerAdded(v)
end

A localscript in a screengui, with a frame:

-- localscript in a playergui that contains a frame - handles gui animations only
local Gui=script.Parent
local Frame=Gui:WaitForChild("Frame")
local Player=game:GetService("Players").LocalPlayer
local Event=Player:WaitForChild("OnPlayerTeleporting")

Event.OnClientEvent:connect(function()
    for i=1,0,-0.1 do
        Frame.BackgroundTransparency=i
        wait(0.1)
    end
end)
Ad

Answer this question