Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I'm building a tycoon. Currently someone can purchase as many tycoons as they want?

Hey guys,

I'm making a homeowners tycoon. Basically, someone is supposed to join the server, pick a house, touch a mailbox, and own the home. Everything works fine, however, when someone already owns a home, they are able to buy another one. This could mean that someone is able to join the server and 'own' every home before anyone even gets to them. I'm not sure how to script this.

The script I'm using for the mailbox is this:

name = script.Parent
owner = name.Parent.OwnerName

while true do
if owner.Value ~= "" then
name.Name = "Homeowner : " .. owner.Value
else
name.Name = "Nobody Lives Here"
end
wait(2)
end

The script I'm using for the ownership is this:

local ting = 0 --debouncer
owner = script.Parent.Parent.Parent.OwnerName
function onTouched(hit)
	if ting == 0 then --debounce check
	ting = 1 --activate debounce
	local check = hit.Parent:FindFirstChild("Humanoid")
		if check ~= nil then --If a human is found, then
			script.Parent.NewHouse:play()
			wait(1)
			script.Parent.NewHouse:remove()
			local thisplr = game.Players:findFirstChild(hit.Parent.Name)
			if (thisplr~=nil) then
				local ownstyc = thisplr:findFirstChild("Tycoon")
				if (ownstyc~=nil) then
					if ownstyc.Value == 0 then
						ownstyc.Value = 1
						owner.Value = thisplr.Name
						local message = Instance.new("Message")
						message.Text = "You NOW own #1"
						message.Parent = thisplr
						wait(0.5)
						message:remove()
						script.Parent.Parent.Name = ""
						script.Parent.CanCollide = false
					elseif ownstyc.Value == 1 then
						local message = Instance.new("Message")
						message.Text = "You ALREADY own #2"
						message.Parent = thisplr
						wait(0.5)
						message:remove()
					end
				end
			end
		end
	ting = 0 --remove debounce
	end
end

1 answer

The common solution for this, at least I think it's common, is to add a BoolValue object into the player when they join the game.

Do not let the player buy a house unless this value is false. When they do buy a house, change it to true, preventing them from buying another.

I'll leave you to make this, but if you have any issues feel free to ask another question.

This discussion is preserved as it was. New answers, comments, and votes are closed.