You are attempting to use a local script to affect objects in the workspace. Instead, use your local script to trigger a remote event located in Replicated Storage in order to teleport the player with a script located in Server Script Storage.
Insert a RemoteEvent named teleportTrigger in Replicated Storage
Here is an example of your local script:
local Players = game:GetService(“Players”)
local player = Players.LocalPlayer
local RepStorage = game:GetService(“ReplicatedStorage”)
local trigger = RepStorage:FindFirstChild(“teleportTrigger”)
—I don’t know where your button and gui instances are located so this is my best guess.
script.Parent.MouseButton1Click:connect(function()
print(“Working...”)
trigger:FireServer()
script.Parent.Parent:Destroy()
end)
Here is the script which is located in Server Script Storage:
local RepStorage = game:GetService(“Replicated Storage”)
local trigger = RepStorage:FindFirstChild(“teleportTrigger”)
local target = game.Workspace:WaitForChild(“teleportPart”)
trigger.OnServerEvent:connect(function(player)
game.Workspace:FindFirstChild(player.Name).HumanoidRootPart.CFrame = target.CFrame * CFrame.new(0,3,0)
end)
This should work make sure you put the right codes in the right scripts. I also wrote this all on my phone(took me a while) so I hope I helped.
7 comments
Have you checked for errors prior to the mouseclick event?
There weren't any errors before mouseclick.
I mean the only thing I could think of is the script itself may accidentally be disabled or you are literally not using A textbutton.
What is the class for script.Parent
What do you mean by that?
Did you make sure script.parent is the button?
Yeah script.Parent is the button