For some reason this code doesnt print out and puts everything in the middle of the base. Does anyone know why this happens and also no errors print out.
‘’''if loadingdata ~= nil then
for n, l in pairs(loadingdata) do
print(l)
local split = string.split(l, " ")
print(split[1])
local item = game.ReplicatedStorage.ObjectFolder:FindFirstChild(split[4])
if item then
print(“item”)
local clone = item:Clone()
clone.Parent = works
-- Calculate the difference in Z-axis between the new player's plot position and the old position
-- Calculate the differences in axes
local zDifference = pos - tonumber(split[3])
local xdifference = posx - tonumber(split[1])
local ydifference = posy - tonumber(split[2])
-- Debug print statements
print("posx:", posx)
print("posy:", posy)
print("pos:", pos)
print("split[1]:", tonumber(split[1]))
print("split[2]:", tonumber(split[2]))
print("split[3]:", tonumber(split[3]))
print("zDifference:", zDifference)
print("xdifference:", xdifference)
-- Rest of the code...
-- Define a threshold value (in studs) for whether to move the models or not
local threshold = 99
-- If the Z-axis difference is greater than or equal to the threshold, move the models
-- Otherwise, keep them at the same position
--local maths = zDifference >= threshold and zDifference or 0
-- Calculate the adjusted positions based on the Z-axis difference
local position2 = Vector3.new(tonumber(split[1])+xdifference, tonumber(split[2]), tonumber(split[3]) + zDifference)
-- Define the orientation of the model (you already have it in the split table)
local orien = Vector3.new(tonumber(split[5]), tonumber(split[6]), tonumber(split[7]))
clone:SetPrimaryPartCFrame(CFrame.new(position2) * CFrame.Angles(math.rad(orien.X), math.rad(orien.Y), math.rad(orien.Z)))
clone:MoveTo(clone.MainPart.Position)
else
warn("cannot find item "..tostring(split[4]))
end
end
else
warn("loading data = nil")
end'''
If it doesn’t even run the else block at the very bottom, that just means the script hasn’t even reached the if statement in the first place. What other code surrounds the entire block of code you posted here?
That code runs on 1 event:
game.Players.PlayerAdded()
‘’'local datastore = game:GetService(“DataStoreService”)
local SaveData = datastore:GetDataStore(“SaveData”)
local inventory = datastore:GetDataStore(“inventory2”)
local plotsave = datastore:GetDataStore(“PlotSave”)
local visits = datastore:GetDataStore(“visits”)
local games = datastore:GetDataStore(“games”)
local boost = datastore:GetDataStore(“Boosts”)
local datastore = game:GetService(“DataStoreService”)
local SaveData = datastore:GetDataStore(“SaveData”)
local inventory = datastore:GetDataStore(“inventory2”)
local plots = game.Workspace:WaitForChild(“Plots”)
game.Players.PlayerAdded:Connect(function(player)
local Home = Instance.new(“BoolValue”)
Home.Name = “IsHome”
Home.Parent = player
local s, e = pcall(function()
loadingdata = SaveData:GetAsync(player.UserId…“-save”)
end)
if not s then warn(e) end
local name = player.Name
local works = nil
local worksp = nil
local plotnumber = 0
local pos = nil
local posy = nil
local posx = nil
for i, v in pairs(plots:GetChildren()) do
if v:FindFirstChild("Claimed").Value == false then
v.Claimed.Value = true
plotnumber = v.PlotNumber.Value
v:FindFirstChild("Owner").Value = name
works = v.Workspace
worksp = v.Workspace
pos = v.Base.Position.Z
posy = v.Base.Position.Y
posx = v.Base.Position.X
print(v.Owner.Value)
break
end
end
for a, e in pairs(game.Workspace.Plot_House:GetChildren()) do
if e.Plot.Value == plotnumber then
e.Owner.Value = player.Name
local s, e = pcall(function()
wait(0.5)
player.Character:WaitForChild("HumanoidRootPart")
player.Character.HumanoidRootPart.CFrame = e.DoorRange.CFrame
end)
end
end
if loadingdata ~= nil then
for _, l in pairs(loadingdata) do
print(l)
local split = string.split(l, " ")
print(split[1])
local item = game.ReplicatedStorage.ObjectFolder:FindFirstChild(split[4])
if item then
print("item")
local clone = item:Clone()
clone.Parent = works
-- Calculate the difference in Z-axis between the new player's plot position and the old position
-- Calculate the differences in axes
local zDifference = pos - tonumber(split[3])
local xdifference = posx - tonumber(split[1])
local ydifference = posy - tonumber(split[2])
-- Debug print statements
print("posx:", posx)
print("posy:", posy)
print("pos:", pos)
print("split[1]:", tonumber(split[1]))
print("split[2]:", tonumber(split[2]))
print("split[3]:", tonumber(split[3]))
print("zDifference:", zDifference)
print("xdifference:", xdifference)
-- Rest of the code...
-- Define a threshold value (in studs) for whether to move the models or not
local threshold = 99
-- If the Z-axis difference is greater than or equal to the threshold, move the models
-- Otherwise, keep them at the same position
--local maths = zDifference >= threshold and zDifference or 0
-- Calculate the adjusted positions based on the Z-axis difference
local position2 = Vector3.new(tonumber(split[1]), tonumber(split[2]), tonumber(split[3]))+Vector3.new(xdifference, 0, zDifference)
-- Define the orientation of the model (you already have it in the split table)
local orien = Vector3.new(tonumber(split[5]), tonumber(split[6]), tonumber(split[7]))
clone:SetPrimaryPartCFrame(CFrame.new(position2) * CFrame.Angles(math.rad(orien.X), math.rad(orien.Y), math.rad(orien.Z)))
clone:MoveTo(clone.MainPart.Position)
else
warn("cannot find item "..tostring(split[4]))
end
end
else
warn("loading data = nil")
end'''
It looks like loadingdata
isn’t even declared outside of the pcall
’s scope. Declare the variable in the top of the script, then try again.
The #1 reason why a print()
method won’t work is because the script hasn’t got to that part yet. Check for parameters and functions that can be pausing this.