EDIT: I see what happened now that you gave me the Output error, but where do you EXACTLY have that SurfaceGui?... oh well, listen,
The script is trying to find an object inside Workspace called "Character", Which does not exist.
You can't just get the player like that.
This has already been asked a few times,
Question 1
Question 2
Question 3
All the answerers said, it's impossible to get a player who clicked in a SurfaceGui.
There are two alternatives.
Both alternatives don't use the SurfaceGui, it would only be for decoration, lol.
Option 1
You will have to add a LocalScript inside StarterGui or StarterPack and just add a simple part with a SurfaceGui Button in Workspace and add a StringValue inside the Button to store the player's name to later find the player with the correct name in playerservice, to later teleport the player it would be really complicated for you, and it's not really efficient.
Option 2
This is the easiest, and the most efficient,
Store a ClickDetector inside a Part, so you can be able to click it, and get teleported thanks to the "player" argument it has included by default, compared to the .MouseButton1Down Event which does not have any.
local ClickDetect=script.Parent
ClickDetect.MouseClick:connect(function(player)
if player.Character then local char=player.Character
if char:FindFirstChild("Torso")==nil then return end
local torso=char.Torso
torso.CFrame=CFrame.new(0,0,0)
end
end)
5 comments
torsocannot benil; I consider it better practice to include the instantiation of theVector3and that was an unnecessary changeDoesn't work ;/
@BlueTaslem True. @McLavaArmy Well, are you sure that is the whole script? Can you give us the output error?
The error is 17:56:36.375 - Character is not a valid member of Workspace 17:56:36.376 - Script 'Workspace.Part.SurfaceGui.TextButton.Script', Line 1 17:56:36.376 - Stack End @6PenTax
Solved, check my answer, I edited it, and remember to please accept the answer and +1 me, also remember to edit your tittle as Solved since you changed it to Unsolved