Trying To Teleport A Group Of Players Data

This script is supposed to recive a teleport of group of players data, but somehow its decided to take a random player points/wins and make it the entire players on the server the same points/wins.

local safeTeleport = require(script.SafeTeleport)
local approvedPlaceIds = {9073506532} -- insert approved PlaceIds here

local function isPlaceIdApproved(placeId)
	for _, id in pairs(approvedPlaceIds) do
		if id == placeId then
			return true
		end
	end
	return false
end


game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local wins = Instance.new("IntValue")
	wins.Name = "Endings"
	wins.Parent = leaderstats
	
	local joinData = player:GetJoinData()
	if isPlaceIdApproved(joinData.SourcePlaceId) then
		local teleportData = joinData.TeleportData

		if teleportData then
			local endData = teleportData.Endings
			wins.Value = endData
			print(player, "data has been collected with", endData, "Endings")
		end
	end
end)

Heres the teleporting to another player script if you can’t find any errors

local TeleportService = game:GetService("TeleportService")
local SafeTele = require(game.ServerScriptService.SafeTp)
	
while true do
	
	for i = 30,0,-1 do
		script.Parent.Parent.CarTP.SurfaceGui.Frame.time.Text = i
		
		if workspace.RoadLane1.CarTP.PlrInCar.Value == 0 then
			workspace.RoadLane1.CarTP.SurfaceGui.Frame.Status.TextColor3 = Color3.fromRGB(255, 255, 0)
			workspace.RoadLane1.CarTP.SurfaceGui.Frame.Status.Text = "NEED PLAYERS"
		end
		
		wait(1)
	end
		
	-- Move truck
	
	-- Reserve server
	
	local players = {}

	for i, v in pairs(script.Parent.Seats:GetChildren()) do
		if v.Occupant then
			print("Occupant found. "..v.Parent.Name)
			
			table.insert(players,game.Players:GetPlayerFromCharacter(v.Occupant.Parent)) -- As the Occupant value is the Humanoid, inside of character (v)
		end
	end
	
	
	if #players > 0 then
		
		workspace.RoadLane1.CarTP.SurfaceGui.Frame.Status.TextColor3 = Color3.fromRGB(255, 0, 0)
		workspace.RoadLane1.CarTP.SurfaceGui.Frame.Status.Text = "TELEPORTING"
		
		workspace.RoadLane1.CarTP.DetectorScript.Disabled = true
		
		for i, v in pairs(players) do
			game.ReplicatedStorage.HideExitGUI:FireClient(v)
		end
		
		for i = 0,150,1 do -- Change 30 to number of studs
			script.Parent:TranslateBy(script.Parent.Hitbox.CFrame.lookVector)
			wait(0.01)
		end
				
		local teleportOpt = Instance.new("TeleportOptions")
		teleportOpt.ShouldReserveServer = true
		
		for i, v in pairs(players) do 
			
			local teleportData = {
				Endings = v.leaderstats.Endings.Value
			} -- Data that I want to teleport
			
			teleportOpt:SetTeleportData(teleportData)
		end	
		
		SafeTele(9122217604, players, teleportOpt)
	
		for i = 0,150,1 do -- Change 30 to number of studs
			script.Parent:TranslateBy(-script.Parent.Hitbox.CFrame.lookVector)
			wait(0.01)
		end
		
		workspace.RoadLane1.CarTP.PlrInCar.Value = 0
		workspace.RoadLane1.CarTP.DetectorScript.Disabled = false
		
	end	
	
end

Here is the video if you need more info about the problem

robloxapp-20240118-1927069.wmv (2.9 MB)

		local teleportOpt = Instance.new("TeleportOptions")
		teleportOpt.ShouldReserveServer = true
		
		for i, v in pairs(players) do 
			
			local teleportData = {
				Endings = v.leaderstats.Endings.Value
			} -- Data that I want to teleport
			
			teleportOpt:SetTeleportData(teleportData)
		end	

You are using SetTeleportData over and over for each player, which overwrites the data that was already on your TeleportOptions instance.

1 Like

Oh thanks, is there a way to fix it?

I just took a closer look, and is there any reason why you’re using TeleportData for leaderstats info? That can be spoofed and should only be used for things like local settings and not important data. What you should do instead is use a datastore and just load their data when they join the place they are teleported to. Datastores are the same across places within an experience. If your main place uses a datastore script, just use that one in the other place. If you do that, there won’t be a need for TeleportData for this case

Also, try using TeleportPartyAsync for teleporting groups of people (if you aren’t already)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.