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

Teleport surfaceGui won't teleport?

So I made this script and I inserted it to Workspace > Part > SurfaceGui > TextButton I need it to teleport me to a brick "SpawnLocation1", but when I clicked the SurfaceGui TextButton, it did nothing, please help


spawn = game.Workspace.SpawnLocation1
player = script.Parent.Parent.Parent.Parent

function onClicked()
	player.Character:MoveTo(spawn.Position)
end

script.Parent.MouseButton1Down:connect(onClicked)

When I clicked it, it didn't work. I saw this error in the output, I'm a newbie scripter so I don't know what how Character is not a valid member of Workspace.

19:54:47.303 - Character is not a valid member of Workspace 19:54:47.305 - Script 'Workspace.Part.SurfaceGui.TextButton.Script', Line 5 19:54:47.307 - Stack End


I have no idea how to fix this.

1 comment

0

Please edit your post to use Lua code formatting

2 answers

✓ Accepted answer

Well, to correct that error, you'd put a LocalScript in StarterGui and put the SurfaceGui itself (NOT the brick) in StarterGui. Then, with the following scripts, you'll be able to access the player.

If you just put it in StarterGui, it's not going to be on the brick. This is where some scripting jumps in. Put this as a LocalScript in StarterGui

repeat wait() until game.Players.LocalPlayer.PlayerGui
game.Players.LocalPlayer.PlayerGui["GUI Name Here"].Adornee = game.Workspace.Part -- Define the path to the part where it's supposed to appear on. You may want to change the Part's name, so it doesn't get mixed up with other parts.

After you've done that, in the button, put the following:

spawn = game.Workspace.SpawnLocation1

function onClicked()
	player = game.Players.LocalPlayer
	player.Character:MoveTo(spawn.Position)
end

script.Parent.MouseButton1Down:connect(onClicked)

Any questions? Make sure to comment.

4 comments

0

Put the script I already have in the StarterGui or in the Workspace > Part > SurfaceGui > TextButton?

0

Forget what I just said. Read my new post.

0

Okay so I tested out the script, it worked perfectly while testing in out in Edit Mode. Altough, it didn't work playing it through the website

0

Nevermind I was doing something wrong and I figured it out. Thanks :D

--Not sure if this will work but, Make it a LOCAL script.

spawn = game.Workspace.SpawnLocation1

player = game.Players.localPlayer

script.Parent.MouseButton1Down:connect(function()
wait()
player.Character:MoveTo(spawn.Position)
end)

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