Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Teleport surfaceGui won't teleport?

Asked by 9 years ago

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.

0
Please edit your post to use Lua code formatting BlueTaslem 18071 — 9y

2 answers

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

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.

0
Put the script I already have in the StarterGui or in the Workspace > Part > SurfaceGui > TextButton? ThunderFang28 5 — 9y
0
Forget what I just said. Read my new post. Shawnyg 4330 — 9y
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 ThunderFang28 5 — 9y
0
Nevermind I was doing something wrong and I figured it out. Thanks :D ThunderFang28 5 — 9y
Ad
Log in to vote
0
Answered by
Adryin 120
9 years ago

--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)

Answer this question