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

Teleport GUI script not working, doesnt print any errors either?

Asked by 5 years ago

The script i have here is simple, when clicked the clicker is teleported to the position of forestbrick, in workspace. This is a normal script in a TextButton, which is in a frame thats in a gui.

function Click()
script.Parent.Parent.Parent.Parent.Character.Head.CFrame = CFrame.new(game.Workspace.forestbrick.Position)
end

script.Parent.MouseButton1Down:connect(Click)

script.Parent.MouseButton1Down:connect(Click)

This script does absolutely nothing. Doesnt even print an error. Where did i mess up??

0
It's not printing anything because it's not running at all, being placed in a Script instead of a LocalScript. Aniline_Purple 266 — 5y
0
Please consider reading my answer Ziffixture 6913 — 5y
0
I don't like being rude, but why did you accept Aniline's answer over mine? I worked very hard on that Ziffixture 6913 — 5y
0
Id mark both of yours if i could. Aniline gave me the code i used, but you helped me understand it more. Trust me, i felt bad doing it haha if i could upvote or something i would. I do appreciate your answer. Octocentillion 15 — 5y

2 answers

Log in to vote
6
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Introduction & Understanding


The reasoning behind this issue is mainly due to FilteringEnabled. Before continuing, please learn more about this by watching this quick video covering a bit of FE, and some reading. It’s mandatory you gather a collective knowledge on this as it is an imposed requirement as of ROBLOX’s Experimental Mode update of early September 2017. It’s also quite interesting and can increase performance between both the Client and the Server.


FilteringEnabled prevents automatic communication of LocalScripts to ServerScripts, primarily to reduce the probability of exploitation. Though because of this, these Scripts have been ultimately divided into their proper relationships.

LocalScripts - Client, ServerScripts - Server

Meaning that any work related or directed towards these categories can only be achievable accordingly. Though loopholes can achieve some amount of work in its opposite.

FilteringEnabled doesn’t fully cut off communication though, it only prevents automatic communication. You can learn how to gain manual connection between these Scripts with RemoteEvents


Going About Fixing Your Issue

GUI’s are apart of the Client. Therefore all they should be Scripted with LocalScripts. Your ServerScript was denied access to the Player thus rendering it useless, being unable to complete it’s designated task. Luckily though, there’s a simple fix for this. Convert your ServerScript to a LocalScript.

Extra Pointers

Your Avitar Will Behead Itself!

• Yes, this is going to occur once your Scripts begin running properly. This is because the Head isn’t classified as the PrimaryPart of the Character. Think of PrimaryPart as the Part that everything else attaches itself to, meaning wherever it goes, they go. Since the Head isn’t the PrimaryPart, the Characters attempted reposition won’t follow through, instead, removing the Head from the Rig. - Your Player will die.

Consider targeting the HumanoidRootPart for R15 or Torso for R6. For Universal compatibility refer to Character.PrimaryPart

There Are Different, Easier Ways To Teleport Players

• The path you're taking is quite unnecessary, though it still works there are faster, easier methods that potentially are smoother and more efficient. Since the Character is a Model, I suggest using :SetPrimaryPartCFrame() or :MoveTo().You can read more about this here and here too

Lowercase Connect Was Deprecated

• Though this still works, it's preferred that all developers become accustomed to the renewed functions. Please use :Connect().


References & Read-ups

Eperimental Mode | Lay-over video | Stackoverflow post | Remote Events | Primary Parts


Hope this helps! Or brings you into the world of FE, if so don’t forget to accept and upvote! Questions, like me to further interpret? Comment!

0
Thank you :) this really helps me wrap my head around it more Octocentillion 15 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

There are a few issues with your code:

  1. GUI and player input related will not run in a Script, they will only be executed in LocalScript objects that can run client side code. Scripts are used for server side code.

  2. To teleport a player, you should reference the HumanoidRootPart instead. Changing the CFrame of the HumanoidRootPart is the usual way of teleporting players. Any other part will not work, such as in your example, it would only kill the player.

Here's the code for a LocalScript inside a TextButton/ImageButton:

function Click()
-- reference the Player
local Player = game:GetService("Players").LocalPlayer

-- get the character, assuming that it's already there
local Character = Player.Character

-- get the root part (HumanoidRootPart), assuming it's already there
local HRP = Character.HumanoidRootPart

-- teleport by changing the CFrame to 
-- a CFrame with the same position as the forestbrick
HRP.CFrame = CFrame.new(workspace.forestbrick.Position)

end

script.Parent.MouseButton1Down:connect(Click)

Note that for all of these, I assumed that the parts and references I made were already loaded. There could be errors which could be fixed using :WaitForChild(childname), but that's beyond the scope of this problem.

I suggest you read up on more guides about scripting. Hope that helps!

0
what the hell User#24403 69 — 5y

Answer this question