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

Issues with trying to teleport a player to a different place?

Asked by 4 years ago
Edited 4 years ago

I don't know what I need to do in order for this to work, help would be appreciated, I am trying to see if the player who clicked on the play gui button has any data stored in a data storage location. If they don't I want to teleport them to a tutorial place, but when I click the play button nothing happens and it gives me an error on the teleportation line

Error:

18:10:36.618 - Unable to cast value to Object

18:10:36.618 - Stack Begin

18:10:36.619 - Script 'ServerScriptService.Script', Line 14

18:10:36.619 - Stack End

Local Script:

--Variables
local camera  = workspace.CurrentCamera
local camPart = workspace.maincam
local frame = script.Parent:WaitForChild("Frame")
local PlayBtn = frame:WaitForChild("Play Button")
local Credits = frame:WaitForChild("Credits")
local Title = frame:WaitForChild("Title")
local GamePopup = script.Parent:WaitForChild("Loadingtxt")   
local repstorage = game:GetService("ReplicatedStorage")
local event = repstorage:WaitForChild("noob")

spawn(function()


    camera.CameraType = "Scriptable"

        camera.CFrame = camPart.CFrame
        frame.Visible = true

end)

PlayBtn.MouseButton1Click:Connect(function()
    GamePopup.Visible = true
    local player = game.Players.LocalPlayer 
    event:FireServer(player)
end)

Server Script:

local DataStoreService = game:GetService("DataStoreService")
local tpService = game:GetService("TeleportService")

local Tutorial = 4653251860
local Playground = ...
local newplayer = DataStoreService:GetDataStore("NoobCheck")
local repstorage = game:GetService("ReplicatedStorage")
local event = repstorage:WaitForChild("noob")

local function checkplayer(player)
    local check
    check = newplayer:GetAsync(player.UserId.."-test")
    if(check == nil)then
        tpService:Teleport(Tutorial,player.UserId)
    else
        tpService:Teleport(Playground,player.UserId)
    end
end

event.OnServerEvent:Connect(checkplayer)

1 answer

Log in to vote
0
Answered by
ArtBlart 533 Moderation Voter
4 years ago

According to the documentation of TeleportService, The method :Teleport takes a player object, not the UserId of the player.

Just remove .UserId from your arguments and you should be fine.

0
thank you! cyanslime123 23 — 4y
Ad

Answer this question