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

How to make a teleporter SurfaceGui ?

So i want to create a surface gui with a textbutton inside that when a player press it he got teleported to a coordinate The problem is that i found this script :

-- SurfaceGUI script, made by Jaitix!

--Put this in StarterGui, ALWAYS!
TeleportBack = game.Workspace.BackWall.Back.Frame.TeleportBack
-- Identifies TextButton
local player = game.Players.LocalPlayer
TeleportBack.MouseButton1Click:connect(function()  
	--if TextButton is Clicked, then
	if player.Character and player.Character:FindFirstChild("Torso") then
		-- if player and the character, and if it finds the torso
		-- of the character
		player.Character.Torso.CFrame = CFrame.new(29.184, 24, 35.262)
		-- Teleports the player's torso to a new CFrame
		-- Teleporting the torso makes it so the whole player
		-- teleports to the CFrame coordinates
	end
end)

This script is a LocalScript inside the StarterGui it work well in studio but in game it doesnt work and i got 0 error so i dont know what is the problem here so if you know help me ;)

2 answers

✓ Accepted answer

Network Filtering


Due to the forced Network Filtering, localscripts like this do not work in game,in local servers or in the accurate studio update. Network Filtering,more commonly known as Filtering Enabled for FE, is a forced onto all roblox games , and it ensures client-server separation.

To communicate within a FE game,you would use remote events and remote function. And in your case, you would have to use the FireServer function and the OnServerEvent event of the remote event,in order to communicate from the client to the server.


difference between SetPrimaryPartCFrame and setting the primary part


I don't recommend simply moving the hrp or the torso, but rather using the SetPrimaryPartCFrame function. There is a difference between using the set primary part cframe function and setting the cframe of the primary part of a model directly is apparent if you compare the following two scripts in a two part model, with one of the parts as the primarypart:

local model = workspace.Model

model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame()*CFrame.Angles(0,math.rad(1),0))

and

local model = workspace.Model

model.PrimaryPart.CFrame = model:GetPrimaryPartCFrame()*CFrame.Angles(0,math.rad(1),0))

You will find that the first script moves both objects and the 2nd only moves the primary part


Application


local plr = game.Players.LocalPlayer
local button = plr.PlayerGui.ScreenGui.Button
local remote = game.ReplicatedStorage.RemoteEvent

button.MouseButton1Click:Connect(function()
	remote:FireServer()
end)

Server:

local remote = game.ReplicatedStorage.RemoteEvent
remote.OnServerEvent:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	char:SetPrimaryPartCFrame(CFrame.new(29.184, 24, 35.262))
end)

Hopefully this helped!

Please make your own scripts, Its against website rules.

But you need to put the Surface Gui inside of StarterGui

and change the Adornee to the Part

Accept if this helped :D

add a script inside the surface gui

local gui = script.Parent
local part = game.Workspace.Part
gui.Adornee = part

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