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??
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.
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.
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()
.
• 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!
There are a few issues with your code:
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.
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!