Housing Purchasing System

Ive been working on a door script, that only allows the owner of the house open a door once bought, how do I recognize the owner of this house and make it to where it recognizes the username and opens the door for the owner?

local buypart = script.Parent.Parent.BuyPart
local labelpart = script.Parent.Parent.LabelPart
owned = false
price = 200
open = false

buypart.ClickDetector.MouseClick:Connect(function(player)
	local cash = player.leaderstats.Cash
	if cash.Value >= price and owned == false then
		labelpart.BillboardGui.TextLabel.Text = player.Name.."'s House"
		cash.Value = cash.Value - price
		owned = true
	else
		print(player.Name.." cannot afford house!")
	end
end)
1 Like

Well this is DEFINITELY not the best way to do this but I’ll try to do the dumbest way that will work.

So you’ll just add a StringValue inside the house and change the value of it to the player’s name. Then when a player touches the door or something, then check the value of the StringValue on the server.

Just like @D00M3D_Dev Explained, you could also do something similar using an Attribute on the Door. Just make sure to Set/Get this Attribute and confirm on the server to make sure it cannot be exploited.

Attribute? How would I write that out? Like the string value?

Oh okay I know what an attribute is now