Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

why isnt the teleport script working?

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)

1 answer

✓ Accepted answer

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.

3 comments

0

Also take note of the way I set the CFrame

0

Bro thanks so much it finally works now!

0

No problem bro

This discussion is preserved as it was. New answers, comments, and votes are closed.