Hello. I’m trying to teleport a user from one part to part while it’s spawned. But for some reason it won’t teleport.
This is my code:
Player.CharacterAdded:Connect(function(Character)
for Index, Part in pairs(Character:GetChildren()) do
if Part:IsA("BasePart") then
Part.CollisionGroup = "Player"
print("Set "..Part.Name.."'s collision group.")
end
end
local Checkpoint = CheckpointsFolder:FindFirstChild(tostring(Level.Value)) or workspace.Spawn
print(Checkpoint.Name)
if not Checkpoint then warn("Checkpoint "..Checkpoint.." not found while teleporting "..Player.Name..".") return end
Character:PivotTo(Checkpoint.CFrame * CFrame.new(0, 5, 0))
end)
The print statements work too, but it doesn’t show any errors or anything.
Interesting, the script seems to work for me. Could you recheck if Checkpoint is a BasePart? If that doesn’t work you may have to wait until the HumanoidRootPart loads using :WaitForChild()
Yes, checkpoint is a BasePart. I checked using :IsA. I don’t think :WaitForChild is necessary because it is able to set it’s collision group so it’s probably already loaded.
I can’t wait for the teleportation as it is a checkpoint, it needs to teleport immediately. :MoveTo didn’t work either, nor did setting the character’s and HRP’s CFrame manually.
No, this is a normal CFrame. I am puzzled as this works fine with me, are you sure there isn’t any other “teleportation” function interfering with this? If not could I see a bit more of the script please.
No there’s no other teleportation script.
Here’s the whole script:
local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PhysicsService = game:GetService("PhysicsService")
local BadgeService = game:GetService("BadgeService")
PhysicsService:RegisterCollisionGroup("Player")
PhysicsService:CollisionGroupSetCollidable("Player", "Player", false)
local DataStore = DataStoreService:GetDataStore("Main")
local RemoteEvents = ReplicatedStorage.RemoteEvents
local ChatMessageEvent = RemoteEvents.ChatMessage
local CheckpointsFolder = workspace:WaitForChild("Checkpoints")
local WelcomeBadgeID = 2125710098
Players.PlayerAdded:Connect(function(Player)
local AreNamesSame = Player.Name == Player.DisplayName
if Player.UserId == game.CreatorId then
local Message = not AreNamesSame and "The Owner has joined! Welcome, "..Player.DisplayName.." (@"..Player.Name..")!" or "The Owner has joined! Welcome, "..Player.DisplayName.."!"
ChatMessageEvent:FireAllClients(Message, Color3.fromRGB(45, 220, 255))
else
local Message = not AreNamesSame and "A player has joined! Welcome, "..Player.DisplayName.." (@"..Player.Name..")!" or "A player has joined! Welcome, "..Player.DisplayName.."!"
ChatMessageEvent:FireAllClients(Message, Color3.fromRGB(255, 255, 255))
end
if not BadgeService:UserHasBadgeAsync(Player.UserId, WelcomeBadgeID) then
BadgeService:AwardBadge(WelcomeBadgeID)
end
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local Money = Instance.new("IntValue")
Money.Name = "$$"
local Rebirths = Instance.new("IntValue")
Rebirths.Name = "Rebirths"
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Parent = leaderstats
Rebirths.Parent = leaderstats
Money.Parent = leaderstats
local Data = nil
local Success, Error = pcall(function()
Data = DataStore:GetAsync(Player.UserId) or {}
end)
if not Success then warn("Failed to fetch "..Player.Name.."'s data.") end
Money.Value = Data.Money or 0
Rebirths.Value = Data.Rebirths or 0
Level.Value = Data.Level or 1
Player.CharacterAdded:Connect(function(Character)
for Index, Part in pairs(Character:GetChildren()) do
if Part:IsA("BasePart") then
Part.CollisionGroup = "Player"
print("Set "..Part.Name.."'s collision group.")
end
end
local Checkpoint = CheckpointsFolder:FindFirstChild(tostring(Level.Value)) or workspace.Spawn
print(Checkpoint.Name)
print(Checkpoint.CFrame)
if not Checkpoint then warn("Checkpoint "..Checkpoint.." not found while teleporting "..Player.Name..".") return end
local HumanoidRootPart = Character.PrimaryPart
Character:PivotTo(Checkpoint.CFrame + Vector3.new(0, 5, 0))
print("Teleported.")
end)
end)
Players.PlayerRemoving:Connect(function(Player)
pcall(function()
local leaderstats = Player.leaderstats
local Money = leaderstats["$$"].Value
local Rebirths = leaderstats.Rebirths.Value
local Level = leaderstats.Level.Value
local Data = {
["Money"] = Money,
["Rebirths"] = Rebirths,
["Level"] = Level
}
DataStore:SetAsync(Player.UserId, Data)
end)
end)
game:BindToClose(function() task.wait(4) end)
I’ve played around with this script a little, and I can’t seem to find why it doesn’t work for you. It works for me and some other people on this thread. Maybe you could try to locate any other scripts that could be affecting the player at all, you could try to put the server script inside of a new studio place, and see if it’ll work for you. If it does it means there is something you messed up along the way originally. You could also try to delete the checkpoints and then replace them and see if that fixes the issue. Make sure to double check all the names and everything. Again not sure why this isn’t working for you.