I am currently having trouble with this code, is anyone able to help?
**local TeleportService = game:GetService(“TeleportService”)
local gameID = game.teleportblock.GameIDValue.Value
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
TeleportService:Teleport(gameID, player)
end
end)**
You haven’t defined the hit variable, meaning that when you call it with GetPlayerFromCharacter, the script has no clue what you are referring to. All you have to do is include it in the parenthesis following function.
You can’t get the player from a MouseButton1Click event, unfortunately. You would have to use a LocalScript to detect the click and then FireServer with a RemoteEvent. Or you could just teleport with a LocalScript and just use the LocalPlayer, like Wizard said.
I misread and thought it was using a clickdetector, my bad.
So, assuming it is a gui use LocalPlayer. If it is a surface gui you will get some other issues, as you would have to set the surfacegui’s adornee to whatever part you want it to be on and parent the surfacegui to the startergui for it to work properly.