Error with tycoon plot manager

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

1 Like

Shouldn’t you be getting the Plot which was previously owned by the Player leaving? Instead of:

Can’t you just run:

if plot:GetAttribute('Owner') == player.UserId then
		-- Code down here runs on the player that left
		plot:SetAttribute("Taken", nil)
		plot:SetAttribute('Owner', nil)
end	
1 Like

I’ll try it and mark your answer as a solution if it works! :slight_smile:

It worked!!! Thanks so much!!! :slight_smile:

1 Like

I just realized, so basically the whole thing is a server script, would I make an event that plays the button sound and fire it on the client? I don’t know what would work… but if it doesn’t work I can think of other solutions.

Don’t get this. Is this still related to the original issue?

If not, I would suggest making a new topic for this

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.