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

GetPlayerPlaceInstanceAsync has to be called from the server?

Asked by 5 years ago
Edited 5 years ago

I'm trying to experiment with a teleport menu, and here's what it looks like

LocalScript:

script.Parent.MouseButton1Click:Connect(function()
    local rs = game:GetService("ReplicatedStorage")
    local teleport = rs:WaitForChild("Teleport")
    teleport:FireServer(script.Parent.Parent.Parent.ObjectValue.Value)
end)

ServerScript:

local rs = game:GetService("ReplicatedStorage")
local teleport = Instance.new("RemoteEvent", rs)
teleport.Name = "Teleport"

local function onReceive(plr, value)
    local frame = value
local one = frame:FindFirstChild("one")

local teleportService = game:GetService("TeleportService")

function meow(plr, targetuserid)
    targetuserid = one.Text
    if targetuserid then
        local success, errorMsg, placeId, instanceId = teleportService:GetPlayerPlaceInstanceAsync(targetuserid)
        if success then
            teleportService:TeleportToPlaceInstance(placeId, instanceId, plr)
        else
            print ("Teleport failed:", errorMsg)
        end

    end

end
meow()
end

teleport.OnServerEvent:Connect(onReceive)

Always says need to be called from the server, even though it is.

Help is appreciated!

Answer this question