So, I'm trying to make it so a player can tp somewhere by clicking a button. But, I just can't figure out how to get the script to find out who the player is. I tried using "LocalPlayer" but that gets the player in "Players" service not in workspace. What do I do?
local Player = workspace.LocalPlayer game.ReplicatedStorage.BackToLobby.OnServerEvent:Connect(function() Player.Character.HumanoidRootPart.CFrame = CFrame.new(-44.093, 3.225, 35.84) end)
funny thing,
there is a parameter in OnServerEvent, which references the player who fired the event. so you can just do this:
local RS = game:GetService("ReplicatedStorage") RS.BackToLobby.OnServerEvent:Connect(function(player) player.Character.HumanoidRootPart.CFrame = CFrame.new(-44.093, 3.225, 35.84) end)
To get the players character you change
local Player = workspace.LocalPlayer
To this
local Player = script.Parent
Then the script should be
local Player = script.Parent game.ReplicatedStorage.BackToLobby.OnServerEvent:Connect(function() Player.HumanoidRootPart.CFrame = CFrame.new(-44.093, 3.225, 35.84) end)