How to check if a player is not owner of a tycoon?

Hi Guys, so basically I’m making a sandbox tycoon game and I made a module which assigns a tycoon. So my problem is that a player can own 2 tycoon whenever they touch a tycoon door. Like they own a tycoon, they touched another tycoon and now owns 2 tycoons. It can be fixed using Values but I don’t want to go to Value. Is there any better way to do this ? Thanks :slight_smile:

Code-

local tycoon = {}

tycoon.__index = tycoon

function tycoon:New(tycoonfolder, plot, Owner)
	local self = setmetatable({}, tycoon)
	self.Plot = plot
	self.Owner = Owner
	self.Tycoon = tycoonfolder
	tycoonfolder.Door.Main.SurfaceGui.TextLabel.Text = Owner.Name.."'s Tycoon"
	return self
end
return tycoon

Some developers use teams where they assign a tycoon to a certain team and once a player owns that tycoon then touches another tycoon the server checks if they are in another team. I would personally prefer using a bool value to check if the tycoon is already owned and if the player owns another tycoon.

2 Likes

Ok, I could simply do with bool value but I don’t want to use Value for now, so is there any better method for it ?

1 Like

Not that I know of. Bool value is generally the easiest way to do it

2 Likes

Teams
image

not microsoft teams, the teams instance

1 Like

Attributes. Use attributes and set attributes for every player who’s in a tycoon. Like so:

local tycoon = {}

tycoon.__index = tycoon

function tycoon:New(tycoonfolder, plot, Owner)
	if Owner:GetAttribute("OwnsTycoon") then return end
	local self = setmetatable({}, tycoon)
	self.Plot = plot
	self.Owner = Owner
	self.Tycoon = tycoonfolder
	Owner:SetAttribute("OwnsTycoon", true)
	tycoonfolder.Door.Main.SurfaceGui.TextLabel.Text = Owner.Name.."'s Tycoon"
	return self
end
return tycoon

Please, now handle your script accordingly on the edge case that tycoon:New returns nil, as that is now a possibility if the player already owns a tycoon.

3 Likes

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