IMO, the code should look more like this:
Button Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local button = script.Parent
local humanEvent = ReplicatedStorage:WaitForChild("HumanEvent")
button.MouseButton1Click:Connect(function()
humanEvent:FireServer()
end)
Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local humanEvent = ReplicatedStorage:FindFirstChild("HumanEvent")
if humanEvent then
humanEvent.OnServerEvent:Connect(function(player)
if player.Character and player.Character.Parent == game.Workspace then
player.Character:MoveTo(Vector3.new(-144, -2, 46))
end
end)
else
warn("Some message about HumanEvent being nil or misnamed, etc")
end
Optionally, you can teleport characters with player.Character:SetPrimaryPartCFrame(cf) if you need to specify which direction they end up facing, but you lose the automatic height search functionality of MoveTo, so you have to do your own checks to make sure you're sending the player to an open space where they will fit. Some raycasts may be necessary. This is more work, but gives developers more control.
1 comment
it won't work