I’ve got a major issue with this spawn location code…
local Plots = game.Workspace.Plots
local Players = game:GetService('Players')
Players.PlayerAdded:Connect(function(player)
for _, plrplot in Plots:GetChildren() do
if plrplot:GetAttribute('Taken') == true and plrplot:GetAttribute('Owner') == player.UserId then
player.RespawnLocation = plrplot.SpawnLocation
end
end
end)
For some reason the game is spawning the player on the wrong platform even tho i have loop to check for each plot and its attributes that match then set the spawn location and when the player respawns, it changes the spawn location.
Please I need immediate help i cant figure out what i did wrong
local Plots = game.Workspace.Plots
local Players = game:GetService('Players')
Players.PlayerAdded:Connect(function(player)
for _, plrplot in ipairs(Plots:GetChildren()) do
if plrplot:GetAttribute('Taken') == true and plrplot:GetAttribute('Owner') == player.UserId then
player.RespawnLocation = plrplot.SpawnLocation.Position
break -- Exit the loop once good plot found
end
end
end)
local Plots = game.Workspace.Plots
local Players = game:GetService('Players')
Players.PlayerAdded:Connect(function(player)
for _, plrplot in Plots:GetChildren() do
local SpecifcPlrPlot = plrplot
if SpecifcPlrPlot:GetAttribute('Taken') == true and SpecifcPlrPlot:GetAttribute('Owner') == player.UserId then
player.RespawnLocation = SpecifcPlrPlot.SpawnLocation
end
end
end)
script:WaitForChild('CreatePlot').Event:Connect(function(Player, ItemIdsTable)
for _, plot in Plots:GetChildren() do
if plot:GetAttribute('Taken') then continue end
plot:SetAttribute('Taken', true)
plot:SetAttribute('Owner', Player.UserId)
local ItemsFolder = Instance.new('Folder')
ItemsFolder.Name = 'Items'
ItemsFolder.Parent = plot
this is the code that assigns the attributes to the plot
and this is the explorer
they are made in 2 different scripts, but i believe they could be made in the same one
Firstly don’t use pairs for itterating through a folder
local Plots = game.Workspace.Plots
local Players = game:GetService('Players')
Players.PlayerAdded:Connect(function(player)
for _, plrplot in Plots do
local Plot = plrplot
if plrplot:GetAttribute('Taken') == true and plrplot:GetAttribute('Owner') == player.UserId then
player.RespawnLocation = plrplot.SpawnLocation.Position
print("RUN")
break -- Exit the loop once good plot found
end
end
end)