I have a tycoon game where the player touches a door, the money is deducted from their leaderboard stat, and they become the owner of that door. I have a check currently in place where the script checks if the user has a copperTycoon value in their player directory and won't let them buy another door so they don't buy every tycoon in the server.
However, when they go and touch another door that is not owned, another player who doesn't own any tycoons are now no longer able to purchase the door.
owner = script.Parent.Parent.Parent.ownerName
oreMachine = script.Parent.Parent.Parent.machineOn
factoryPrice = 250
local debounce = false
function onTouched(hit)
if (debounce == false) then
debounce = true
local check = hit.Parent:FindFirstChild("Humanoid") --Find the player's humanoid that touched the part.
if (check ~= nil) then --If the check finds a player humanoid, then...
local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Find the player who touched the part among everyone else in the game.
if (player:FindFirstChild("leaderstats"):FindFirstChild("Cash") ~= nil) then
if (player:FindFirstChild("copperFactory") ~= nil) then --Check if the player already owns this type of factory.
-- :)
else
local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Find the player who touched the part among everyone else in the game.
local cash = player.leaderstats.Cash.Value --Sets the player's Cash leaderboard stats to a local variable.
if cash >= factoryPrice then
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - factoryPrice
owner.Value = hit.Parent.Name --Save player's playername in the OwnerName StringValue.
local ownedFactory = Instance.new("StringValue") --Add a StringValue to the player to show the game that they already own this type of factory.
ownedFactory.Name = "copperFactory"
ownedFactory.Parent = player
wait(0.65)
script.Parent:remove() --Delete the Door part.
oreMachine.Value = true --Turn on the machine.
end
end
end
debounce = false
end
end
end
script.Parent.Touched:Connect(onTouched)
Thank you!

3 comments
That fixed the issue completely! I must have missed it or got confused. Thank you!
@T3_MasterGamer you are a cheetah
@ImKirda nob