Hi,
I’m working on a tycoon where if you join the game you’re auto assigned to one of the available plots. When the plot is claimed, the player’s username will show on a sign outside.
The name isn’t updating on the text label for some reason. I’d appreciate help on what I’m doing wrong
This is the localscript in serverscriptservice:
local Players = game:GetService("Players")
local PlotsFolder = workspace:WaitForChild("Plots")
local MAX_PLOTS = 6
local assignedPlots = {}
local function getAvailablePlot()
for _, plot in ipairs(PlotsFolder:GetChildren()) do
if not assignedPlots[plot] then
return plot
end
end
return nil
end
local function assignPlotToPlayer(player)
local plot = getAvailablePlot()
if plot then
assignedPlots[plot] = player
player:SetAttribute("AssignedPlot", plot.Name)
local spawnLocation = plot:FindFirstChild("SpawnLocation")
if spawnLocation then
player.CharacterAdded:Connect(function(char)
char:WaitForChild("HumanoidRootPart").CFrame = spawnLocation.CFrame + Vector3.new(0, 3, 0)
end)
end
local signModel = plot:FindFirstChild("Sign")
if signModel then
local frontPart = signModel:FindFirstChild("Front")
if frontPart then
local surfaceGui = frontPart:FindFirstChildWhichIsA("SurfaceGui")
if surfaceGui then
local textLabel = surfaceGui:FindFirstChildWhichIsA("TextLabel")
if textLabel then
textLabel.Text = player.Name
end
end
end
end
end
end
local function freePlot(player)
for plot, assignedPlayer in pairs(assignedPlots) do
if assignedPlayer == player then
assignedPlots[plot] = nil
local signModel = plot:FindFirstChild("Sign")
if signModel then
local frontPart = signModel:FindFirstChild("Front")
if frontPart then
local surfaceGui = frontPart:FindFirstChildWhichIsA("SurfaceGui")
if surfaceGui then
local textLabel = surfaceGui:FindFirstChildWhichIsA("TextLabel")
if textLabel then
textLabel.Text = "Available"
end
end
end
end
end
end
end
Players.PlayerAdded:Connect(assignPlotToPlayer)
Players.PlayerRemoving:Connect(freePlot)
Explorer: