I have tried by sending a remote event to the sever which just came up with the same error (Unable to cast value to Objects) so i tried in a local script again but it doesnt work
heres the LocalScript:
local tps = game:GetService("TeleportService")
local player = game.Players.LocalPlayer
local M1Button = script.Parent
M1Button.MouseButton1Click:Connect(function()
task.wait(1)
tps:TeleportAsync(PlaceID, player)
task.wait(1)
end)
You should use the Teleport method since you are requesting a teleport in a new thread (which is the function that is contained under the connection)
Make sure that PlaceID is a number, the number should be the ID of the new game you’d like to teleport the player to, I’ll use a placeholder variable for convenience.
Since the script is a LocalScript; you do not need to provide the player that you are teleporting because the game will automatically determine that the LocalPlayer should be teleported.
local teleportService = game:GetService('TeleportService')
local localPlayer = game:GetService('Players').LocalPlayer
local guiButton = script:FindFirstAncestorWhichIsA('GuiButton')
local placeId = 0
guiButton.MouseButton1Up:Connect(function(x: number, y: number)
teleportService:Teleport(placeId)
end)
The changes I’ve made to the code include the usage of camelCase, finding the ‘GuiButton’ class through ancestors, switching to MouseButton1Up as the signal to connect to because most modern UI typically expects the client to somewhat confirm their action by releasing the click they’ve initiated on that button. I’ve also simplified the logic by removing unnecessary task.wait calls, while maintaining functionality.