So I have a really weird thing happening when attempting to teleport the local character who presses a button to a specific spot. I can’t provide a video, because the Linux emulated version won’t stop recording until you stop testing, and then crashes before it can save. Alternatively, you can see my problem with the file below: testworld1.rbxl (188.4 KB)
Also, my code for teleporting is below:
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
wait(5)
local PlayerGui = player.PlayerGui.UITests
PlayerGui.Teleport.MouseButton1Click:Connect(function()
character.HumanoidRootPart.Position=Vector3.new(-17.0341606, 14.1505718, 35.6590919)
end)
Okay now I’m assuming that the problem is that just moving HumanoidRootPart used to be an okay way to do it, but now it’s changed, causing the camera to focus on the HumanoidRootPart, and all other body parts to try to go back to HumanoidRootPart, causing them to fall off the map. Please tell me if I’m right about this and how I would easily change this to get all children necessary without getting others that aren’t (if there are some inside of the avatar that I wouldn’t need)
Thanks again!
@codyorr4 Thanks for the help. I am confused why these below scripts together are not working. Can you review them quickly and see what’s wrong?
Local Script
local player = game.Players.LocalPlayer
local character = player.Character
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("TeleportRemoteEvent")
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
wait(5)
local PlayerGui = player.PlayerGui.UITests
PlayerGui.Teleport.MouseButton1Click:Connect(function()
remoteEvent:FireServer()
end)
Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("TeleportRemoteEvent")
local player = game.Players.LocalPlayer
local character = player.Character
print("Successfully got to Server side from Client")
local function onRemoteEvent ()
character.HumanoidRootPart.Position=Vector3.new(-17.0341606, 14.1505718, 35.6590919)
end
remoteEvent.OnServerEvent:Connect(onRemoteEvent())
Sorry but the saved place doesn’t seem to be showing up yet. Working on it if you’d need it
your not passing the onRemoteEvent function to the event parameter and you’ll also need to grab the player / character differently, also its OnServerEvent not OnRemoteEvent
remoteEvent.OnServerEvent:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
root.Position=Vector3.new(-17.0341606, 14.1505718, 35.6590919)
end)
after fixing this, check your teleport to see if it works, it MAY seem like it worked but if you check the server view you’ll notice issues. (depending on where you teleport)
setting the position like this doesn’t seem to replicate nicely.
@codyorr4 I’ve edited the scripts in the reply above to match what they look like now. They still don’t see to be working. Can you tell me if I understood you wrong?
you need to grab the player differently in server scripts
local function onRemoteEvent(player)
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
root.Position=Vector3.new(-17.0341606, 14.1505718, 35.6590919)
end
you can get the player object from the event itself, and then check to make sure character/root exists before making changes.
@codyorr4 Okay sorry I haven’t done Client-Server in a while. It is now getting from Client to Server, but has an error related to getting the character.
14:33:22.903 ServerScriptService.TeleportServerScript:7: attempt to index nil with 'Character' - Server - TeleportServerScript:7