Teleport Script not working

Try this and see if it works:

Client:

--[[
**if you're trying to teleport the player only on the client. then ignore the remote event and place everything into one local script**
]]
--Variables
local player = game.Players.LocalPlayer;
local playergui = player:WaitForChild("PlayerGui");
local shipUi = playergui:WaitForChild("Ships");
local Holder = shipUi:WaitForChild("Holder");
local Button = Holder:WaitForChild("Button");
local RS = game:GetService("ReplicatedStorage");
local TeleportEvent = RS:WaitForChild("TeleportEvent');

Button.Button1Down:Connect(function())
    TeleportEvent:FireServer(CFrame.new(0,0,0)) -- I Wouldn't recommend letting the client decide the coordinates since it'll be easy for hackers to teleport anywhere
end)

Server:

local RS = game:GetService("ReplicatedStorage");
TeleportEvent = RS:WaitForChild("TeleportEvent");--You'll need to add a remote event into Replicated Storage

TeleportEvent.OnServerEvent:Connect(function(plr, cord)
    local char = plr.Character or plr.CharacterAdded:Wait();
    local humanRP = char:WaitForChild("HumanoidRootPart");
        humanRP.CFrame = CFrame.new(cord) + Vector3.new(0,3.5,0);
end)
local 

I wrote this on here so please correct any misspellings or any inappropriate “end”

Actually exploiters don’t need the remote to teleport

1 Like

I mean, To lower the amount of exploiters, There’s no possible way to get rid of them completely, but if there’s less client-to-server communication, it’ll lower exploits abilities

@EHGTR1903 the code sample I provided, when implemented should work.

@FerbZides please do some research before posting, as mentioned above earlier, the MouseButton1Click event does not have a player parameter so your code will not work. I’ll also suggest some improvements to other ideas proposed


Don’t use dot syntax for services, using :GetService() is always the better option to index services as it creates said service if it doesn’t exist; even though the server has most services instantiated.

Using :WaitForChild() for contents under ReplicatedStorage is unnecessary, they are made available implicitly by the time local scripts run their code so you can safely use dot syntax here.

Using the Button1Down event for a player’s mouse is useless for this case, use the MouseButton1Click event for Gui button objects (which do not have a Button1Down event) and then fire the remote for a player, which is also irrelevant to the Op’s use case.
Using Remote Events will only increase what harm exploiters can bring, they can spam remotes and gain them whatever advantage,

Instead of comparing a bool value like this

if bool == false then if bool == true -- etc. 

You can also do this

  local bool
  if not bool then print("false")
  --alternatively
  if bool then print("true")
3 Likes
--Variables
local debounce = true
local Button = script.Parent
Players = game.Players.LocalPlayer.Character

--Functions

Button.MouseButton1Click:Connect(function(player)
	if debounce then
		Players.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-82.436, 5, -44.474))
		debounce = false
		wait(0.5)
		debounce = true
	end
end)

is this script good or does it need improvement?

One small thing. You should use .Activated() for GuiButtons so it platform wide

Ok made it.
if someone needs the code here it is:

--Variables
local debounce = true
local Button = script.Parent
Players = game.Players.LocalPlayer.Character

--Functions

Button.Activated:Connect(function(player)
	if debounce then
		Players.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-82.436, 5, -44.474))
		debounce = false
		wait(0.5)
		debounce = true
	end
end)