So im currently working on a game that requires plots. but when the player gets a plot i have an object referred to as “StarterModel” in the script. but instead of the object staying upright and above the ground, its spawning embedded into the floor and facing the wrong way. here is the code:;
local Players = game:GetService(“Players”)
local Workspace = game:GetService(“Workspace”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local CONFIG = {
PLOTS_FOLDER_NAME = “Plots”,
SIGN_MODEL_NAME = “Sign”,
SIGN_SUBPART_NAME = “Part2”,
GUI_IMAGE_LABEL_NAME = “ImageLabel”,
GUI_TEXT_LABEL_NAME = “TextLabel”,
TELEPORT_HEIGHT_OFFSET = 5,
STARTER_MODEL_NAME = “StarterModel”,
}
local plotsFolder = Workspace:FindFirstChild(CONFIG.PLOTS_FOLDER_NAME)
if not plotsFolder then return end
local availablePlots = {}
local assignedInServer = {}
local assignedPlots = {}
for _, child in ipairs(plotsFolder:GetChildren()) do
if child:IsA(“BasePart”) then
table.insert(availablePlots, child)
end
end
math.randomseed(tick())
local function updateSignGui(plotPart, player)
if not plotPart or not plotPart:IsA(“BasePart”) then return end
local signModel = plotPart:FindFirstChild(CONFIG.SIGN_MODEL_NAME)
if not signModel or not signModel:IsA(“Model”) then return end
local subPart = signModel:FindFirstChild(CONFIG.SIGN_SUBPART_NAME)
if not subPart or not subPart:IsA(“BasePart”) then return end
local surfaceGui
for _, childGui in ipairs(subPart:GetChildren()) do
if childGui:IsA("SurfaceGui") then
surfaceGui = childGui
break
end
end
if not surfaceGui then
warn("Missing SurfaceGui in sign subpart for plot:", plotPart.Name)
return
end
local imageLabel = surfaceGui:FindFirstChild(CONFIG.GUI_IMAGE_LABEL_NAME)
local textLabel = surfaceGui:FindFirstChild(CONFIG.GUI_TEXT_LABEL_NAME)
if not imageLabel or not imageLabel:IsA("ImageLabel") then return end
if not textLabel or not textLabel:IsA("TextLabel") then return end
if not player then
imageLabel.Image = ""
textLabel.Text = "Available"
return
end
local userId = player.UserId
local userName = player.Name
local success, thumbnailUrl = pcall(function()
return Players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size48x48)
end)
if success and typeof(thumbnailUrl) == "string" then
imageLabel.Image = thumbnailUrl
else
imageLabel.Image = ""
end
textLabel.Text = userName
end
local function spawnStarter(plotPart)
local template = ReplicatedStorage:FindFirstChild(CONFIG.STARTER_MODEL_NAME)
if not template or not template:IsA(“Model”) then return end
local clone = template:Clone()
local primary = clone:FindFirstChildWhichIsA(“BasePart”)
if not primary then return end
clone.PrimaryPart = primary
local pos = plotPart.Position
local yaw = math.rad(plotPart.Orientation.Y)
local targetCFrame = CFrame.new(pos.X, pos.Y - 3.753, pos.Z) * CFrame.Angles(0, yaw, 0)
clone:SetPrimaryPartCFrame(targetCFrame)
clone.Parent = plotPart
end
local function pickRandomPlot()
if #availablePlots == 0 then return nil end
local idx = math.random(1, #availablePlots)
local chosen = availablePlots[idx]
table.remove(availablePlots, idx)
assignedInServer[chosen.Name] = true
return chosen
end
local function assignPlotToPlayer(player)
local userId = player.UserId
if assignedPlots[userId] then
return assignedPlots[userId]
end
local newPlot = pickRandomPlot()
if not newPlot then return nil end
assignedPlots[userId] = newPlot
spawnStarter(newPlot)
return newPlot
end
Players.PlayerAdded:Connect(function(player)
local plotPart = assignPlotToPlayer(player)
if not plotPart then return end
updateSignGui(plotPart, player)
player.CharacterAdded:Connect(function(character)
local hrp = character:WaitForChild("HumanoidRootPart", 10)
if not hrp then return end
local spawnPart = plotPart:FindFirstChild("SpawnLocation")
if spawnPart and spawnPart:IsA("BasePart") then
hrp.CFrame = spawnPart.CFrame + Vector3.new(0, CONFIG.TELEPORT_HEIGHT_OFFSET, 0)
else
hrp.CFrame = plotPart.CFrame + Vector3.new(0, CONFIG.TELEPORT_HEIGHT_OFFSET, 0)
end
end)
end)
Players.PlayerRemoving:Connect(function(player)
local userId = player.UserId
local plotPart = assignedPlots[userId]
if plotPart then
updateSignGui(plotPart, nil)
table.insert(availablePlots, plotPart)
assignedInServer[plotPart.Name] = nil
assignedPlots[userId] = nil
local folderName = "PlayerItems_" .. userId
local itemsFolder = Workspace:FindFirstChild(folderName)
if itemsFolder then
itemsFolder:Destroy()
end
end
end)