Hi, I’m Zephyr, a game developer making his very first tycoon game. I followed a tutorial by AlvinBlox that was made 5 months ago, so it shouldn’t be outdated. This is the error.
As you can see, it prints that I claimed plot 1 but plot 2 was removed from me. Here’s my code.
local plots = game.Workspace.Plots
local players = game.Players
local templatePlot = game.Workspace.templatePlot
players.PlayerAdded:Connect(function(player) -- Fires when player joins
-- Will give player a plot
for num, plot in plots:GetChildren() do
if plot:GetAttribute("Taken") then continue end
-- Code below means plot isnt taken
plot:SetAttribute('Taken', true)
plot:SetAttribute('Owner', player.UserId)
print("Plot "..num.." has been taken by "..player.Name.."!")
-- Load stuff from template plot
local templateButtons = templatePlot:FindFirstChild("Buttons"):Clone()
templateButtons.Parent = plot
for _, button in templateButtons:GetChildren() do
-- Get position of button relative to template plot
-- (Get pivot) is (get CFrame) but for models :)
local relativeCFrame = templatePlot.CFrame:ToObjectSpace(button:GetPivot())
-- with ToObjectSpace, if the plot is at 0,5,0 and the button (paramater)
-- is at 0,8,4, the result would be 0,3,-4
button:PivotTo(plot.CFrame:ToWorldSpace(relativeCFrame))
-- ToWorldSpace basically turns (1,1,1) to (-1,-1,-1)
-- Sets the pivot of button to relative CFrame (Remember line 17)
end
break
end
end)
players.PlayerRemoving:Connect(function(player)
for num, plot in plots:GetChildren() do
if plot:GetAttribute('Owner') then continue end
-- If code down here runs it means plot is owned by someone
if plot:GetAttribute('Owner') == player.UserId then continue end
-- Code down here runs on the player that left
plot:SetAttribute("Taken", nil)
plot:SetAttribute('Owner', nil)
print("Plot "..num.." has been removed from "..player.Name.."!")
break
end
end)
Do you know what might be causing this? If so, please reply down below!
Link to the tutorial:
Tutorial on how to make a tycoon, by AlvinBlox
I don’t want to get stuck on this tutorial because I’ve already learned so many new things and I want to learn more