I was working on my game, And a bug has occured where basically, When the map loads, It kicks all players for “Player has been removed from the DataModel” (Error 291), And it kicks all clients in the game, The weird thing is if i’m testing solo, It works perfectly fine, But when my alt joins, Thats when it kicks all players. Is there a solution for this?
local map = maps[random]:Clone()
map.Parent = workspace
status.Value = "Map chosen "..map.Name
wait(5)
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
local spawnLoc = math.random(1,#map.Teleports:GetChildren())
players[i].Character:MoveTo(map.Teleports:GetChildren()[spawnLoc].Position)
players[i].Character.Parent = workspace.Ingame
map.Data.Music.OST:Play()
game:GetService("ReplicatedStorage"):WaitForChild("Events").Giveitem:Fire()
for i,v in ipairs(game.Lighting:GetChildren()) do
v:Destroy()
end
for i,v in ipairs(map.Data.Lighting:GetChildren()) do
v.Parent = game.Lighting
end
end
end
I feel like it has to do with these 2 lines of code, because error 291 states “This error is shown whenever a player was deleted/destroyed from the game server, or when the player is moved out of Players”. Why? I’m not sure… As these 2 lines look fine to me
Consider messing around with these 2 lines of code, Maybe instead of MoveTo() use PivotTo(), or other ways to write these 2 lines of code
Why dont you try to simply cancel the “teleport” and first see if that actually fix the error 291 which is the reason of your post, if that works, then, you can deal with the CFraming, pivot thing
Tried that, It still didn’t work. I also tried cancelling the teleport as @Dev_Peashie suggested, And it still kicked me. I find that extremely strange.
Also as stated prior, It only kicked me on multiplayer, in studio and testing solo it works fine,
I haven’t found anything there, Weirdly enough; It only happened after I added the item giver script thismorning?
Okay I just tested, While testing I commented out the item giver, And it worked.
Only problem is I kind of need the item giver script for the game to work ect.
Here are the item giver scripts:
game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("Giveitem").Event:Connect(function()
print("YESSSSSSSSSSSS IT GAVE THE ITEM")
game:GetService("ReplicatedStorage"):WaitForChild("Events").GiveitemHandler:Fire(script.Parent.Name)
end)
Script 2:
local function giveallplayers(tool)
for i,v in pairs(game.Players:GetPlayers()) do
if v.Character then
if v:FindFirstChild("Backpack") then
if not v.Backpack:FindFirstChild(tool.Name) then
if not v.Character:FindFirstChild(tool.Name) then
local newtool = tool:Clone()
newtool.Parent = v.Backpack
end
end
end
end
end
end
local function unloadalltools()
for i,v in pairs(game.Players:GetPlayers()) do
if v.Character then
if v.Character:FindFirstChildOfClass("Tool") then
v:Destroy()
elseif v.Backpack:FindFirstChildOfClass("Tool") then
v:Destroy()
end
end
end
end
game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("GiveitemHandler").Event:Connect(function(map)
print(map)
if map == "Roblox Classical: Swordfight" then
giveallplayers(script.Sword)
end
end)
game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("GiveitemHandler").Event:Connect(function(map)
unloadalltools()
print("(hopefully) Unloaded!")
end)
I’ll look into this, But anything immediate that could be the issue?