when a button is clicked on the gui i need the player to tp to a location
heres the local script under the button:
script.Parent.MouseButton1Click:Connect(function() local locationofred = game.Workspace.RedSpawn.CFrame game.ReplicatedStorage.Teleporter:FireServer(locationofred) end)
here is the server script after the event is fired:
game.ReplicatedStorage.Teleporter.OnServerEvent:Connect(function(player, location) local playerlocation = player.Character.HumanoidRootPart.CFrame local partlocation = location playerlocation = CFrame.new(partlocation) end)
Hello,
the problem is the following:
local playerlocation = player.Character.HumanoidRootPart.CFrame
When storing the CFrame of the HumanoidRootPart, you actually created a copy rather than a reference to the CFrame. Instead, you should just write your function like this:
game.ReplicatedStorage.Teleporter.OnServerEvent:Connect(function(player, location) player.Character.HumanoidRootPart.CFrame = location end)
Also, setting the CFrame by object.CFrame = CFrame.new(otherObject.CFrame) does not work because the .new keyword is there to create a new CFrame object with the first argument as a Vector3 (or alternatively, three number values).
Hope this helps.