When I teleport a player, it disappears completely from the game, If I teleport it with a Script it is visible on the server but not for the client, I really don’t know why. if anyone has an idea I thank them in advance
local Player = game.Players.LocalPlayer
local Campaign = game.Workspace.Levels.CampaignLevel
Player.Character:MoveTo(Campaign.AvatarPosition.Position)
repeat wait() until game.Players.LocalPlayer.Character
local Player = game.Players.LocalPlayer
local Campaign = game.Workspace.Levels.CampaignLevel
Player.Character.HumanoidRootPart.Position = Campaign.AvatarPosition.Position
You don’t use MoveTo() to teleport the player. That is used to make the player walk somewhere, which isn’t what you wanted. Instead, modify the CFrame of the HumanoidRootPart. I recommend learning a bit more about CFrames since they are pretty useful to learn.
Here is a script you can test:
local Player = game.Players.LocalPlayer
local Campaign = game.Workspace.Levels.CampaignLevel
local character = Player.Character or Player.CharacterAdded:wait()
local root = character:WaitForChild("HumanoidRootPart")
root.CFrame = CFrame.new(Campaign.AvatarPosition.Position)
If this doesn’t really work, try using a RemoteEvent to trigger a normal script that will teleport the player rather than teleporting the player directly in a LocalScript, but the script should hopefully work.
--Change the Avatar
local character = Player.Character or Player.CharacterAdded:wait()
local root = character:WaitForChild("HumanoidRootPart")
root.CFrame = CFrame.new(Campaign.AvatarPosition.Position)
Also, you don’t need to have a RemoteEvent for the teleportation, as I just realized. Is there any reason why you have the teleportation done in a LocalScript? Is it for like a teleportation tool or a button on the screen?
This might be a weird bug, as trying it inside a LocalScript completely messes up the Player’s camera & movement actions
If you’re wanting to move a character via RemoteEvents, I can give you a brief example on how that can be done:
--Client
local Event = game.ReplicatedStorage:WaitForChild("Event")
print("This event has been fired on the client")
Event:FireServer()
--Server
local Event = game.ReplicatedStorage:WaitForChild("Event")
Event.OnServerEvent:Connect(function(Player)
print("This event has been received by the client")
Player.Character.HumanoidRootPart.Position = --Position where you want the character to end
end)
I see. You teleport upon clicking “Join Campaign”.
I just realized that I need to see the entire local script (i.e. the script for the button), as I noticed that you only showed bits of the code, but not the entire code. Also, you don’t need to use RemoteEvent to teleport, as I also realized, so the problem is something different.
local Button = script.Parent
local Campaign = game.Workspace.Levels.CampaignLevel
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local RS = game:GetService(“ReplicatedStorage”)
local CampaignEvent = RS.Events.TeleportCampaign
local Player = game.Players.LocalPlayer
local TS = game:GetService(“TweenService”)
local AvatarEvent = RS.Events.Avatar
Button.MouseButton1Click:Connect (function()
local Button = Player.PlayerGui.CampaignChoice.CampaignFrame.Join
local tweenInfo = TweenInfo.new(0.5)
local tween = TS:Create(Button, tweenInfo, {BackgroundTransparency = 1, TextTransparency =1})
tween:Play()
tween.Completed:Connect(function()
Button.Parent.Parent.Enabled = false
end)
local character = Player.Character or Player.CharacterAdded:wait()
local root = character:WaitForChild("HumanoidRootPart")
root.CFrame = CFrame.new(Campaign.AvatarPosition.Position)
I noticed that when you posted code, it’s not properly formatted. Please try to properly format code so that it is easier for other people to read (4 spaces = tabs, surround the entire code with ``` on top and on the bottom). I decided to be generous and properly formatted your code for you. You’re welcome!
Your LocalScript:
local Button = script.Parent
local Campaign = game.Workspace.Levels.CampaignLevel
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local RS = game:GetService(“ReplicatedStorage”)
local CampaignEvent = RS.Events.TeleportCampaign
local Player = game.Players.LocalPlayer
local TS = game:GetService(“TweenService”)
local AvatarEvent = RS.Events.Avatar
Button.MouseButton1Click:Connect (function()
local Button = Player.PlayerGui.CampaignChoice.CampaignFrame.Join
local tweenInfo = TweenInfo.new(0.5)
local tween = TS:Create(Button, tweenInfo, {BackgroundTransparency = 1, TextTransparency =1})
tween:Play()
tween.Completed:Connect(function()
Button.Parent.Parent.Enabled = false
end)
--Change the camera
Camera.CameraType = Enum.CameraType.Scriptable
Player.Character.Parent = nil
Camera.CFrame = workspace.Levels.CampaignLevel.CameraPlayer.CFrame
--Active scripts
workspace.Levels.CampaignLevel.Limit.Script.Disabled = false
--Change the Avatar
--AvatarEvent:FireServer(Player)
--Player.Character:MoveTo(Campaign.AvatarPosition.Position)
local character = Player.Character or Player.CharacterAdded:wait()
local root = character:WaitForChild("HumanoidRootPart")
root.CFrame = CFrame.new(Campaign.AvatarPosition.Position)
end)
There is one line that stick out to me as the most likely source of the problem:
Player.Character.Parent = nil
Here’s a tip: never do this!!!. This is most likely the reason why what you have shown in the video is happening; It’s not because of the RemoteEvent (Which you don’t need at all) teleporting the player to the server, but it’s because you are essentially deleting the player’s character out of existence. Is there any reason why you wrote this? I have a feeling the reason is related to the camera, since it is in the same section of code. I want to ensure that you never have to do this when dealing with the camera, so please remove that line and test the code again. Hopefully, it should work as intended.
Thank you so much ! Indeed I forgot to remove this line of code which belonged to an old script, I’m really stupid. Thanks again for the time spent helping me that’s really kind