Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't this SurfaceGUI teleport script work? [STILL UNANSWERED]

This is in a SurfaceGUI connected to a button.

Why isn't this working? Please answer this asap!

torso = script.Parent.Parent.Parent.Parent.Character.Torso

function onClicked(GUI) 
		torso.CFrame = CFrame.new(Vector3.new(-432, 2.2, 64)) 
end 

script.Parent.MouseButton1Click:connect(onClicked) 

Best regards, Nathan.

~ Lava, from freedom comes elegance. ~

1 answer

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.

--Inside ClickDetector
local ClickDetect=script.Parent

ClickDetect.MouseClick:connect(function(player) -- Player argument.
if player.Character then local char=player.Character --Check for Character
if char:FindFirstChild("Torso")==nil then return end --Check for Character's Torso
local torso=char.Torso
torso.CFrame=CFrame.new(0,0,0)
end
end)

--Not guaranteed to work since I'm not in ROBLOX Studio right now.

5 comments

0

torso cannot be nil; I consider it better practice to include the instantiation of the Vector3 and that was an unnecessary change

0

Doesn't work ;/

0

@BlueTaslem True. @McLavaArmy Well, are you sure that is the whole script? Can you give us the output error?

0

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

0

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

This discussion is preserved as it was. New answers, comments, and votes are closed.