Buy only one model

Hi im a noob. This code is giving a bit of trouble. No errors tho.

  1. What do you want to achieve?
    I have this in a model, and when I duplicate the model, I don’t want the player to buy both stalls. only one in the workspace.

  2. What is the issue?
    I know the issue is the way i’m going i am coming at the script design. Brain just abit over fried. I’m not getting any errors. just the executions of making this happen.

  3. What solutions have you tried so far?
    Solutions tried… I put print statements all over to make sure but strange, its like it skips past the else and print both after buying the either the first and also the second house.

Script im using ----

stallprice = script.Parent.Parent:WaitForChild("Price")

currentowner = script.Parent.Parent:WaitForChild(“CurrentOwner”)

script.Parent.ClickDetector.MouseClick:Connect(function(player)
local worktab = game.Workspace:GetChildren()

if player:FindFirstChild("leaderstats") and player.Name ~= currentowner.Value and currentowner.Value == "" then
		--Check to make sure people doesnt buy more than one Stall
	for i,v in pairs(worktab) do
		if v.Name == (player.Name.."'s Stall") then
			print("have a stall")
		else
			print("doesnt have a stall")
			
			if player.leaderstats.Coins.Value >= stallprice.Value then
				script.Parent.Parent.Name = player.Name.."'s Stall"
				script.Parent.FrontGui.TextLabel.Text = player.Name.."'s Stall"
				
				player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - stallprice.Value
				script.Parent.Parent.CurrentOwner.Value = player.Name
			end
		end	
	end
end

end)

end)

Outputs were:
doesnt have a stall (x25)
have a stall
Then clicking on second house
doesnt have a stall (x21)
have a stall

1 Like

After some sleep and 2 1/2 more hours working hard on this script. I am proud of myself. i have the solution.
made a for loop, then added 3 varibles. and an instance into a folder where the models were. then remove the instance in the sell script ( which is another script) when i sell. Im so proud of myself. If you guys see anything that would cause lag, please tell me, and bring a solution cause… my brain is OP!!! #learningisawesome!

stallprice = script.Parent.Parent:WaitForChild(“Price”)
currentowner = script.Parent.Parent:WaitForChild(“CurrentOwner”)

script.Parent.ClickDetector.MouseClick:Connect(function(player)

local function makestring()
local have = Instance.new(“StringValue”,game.Workspace.Lots)
have.Name = player.Name
have.Value = 1
end
local have = false
local werid = false
local loop = false
local lottab = game.Workspace.Lots:GetChildren()
for i,v in pairs(lottab) do
if v.Name ~= player.Name then
werid= true
else
have= true
end
end
loop = true
– simaltion test (have= true, werid = true, loop = true)

	if loop == true and have == false and player:FindFirstChild("leaderstats") and player.Name ~= currentowner.Value and currentowner.Value == "" then				
		if player.leaderstats.Coins.Value >= stallprice.Value then
			script.Parent.Parent.Name = player.Name.."'s Stall"
			script.Parent.FrontGui.TextLabel.Text = player.Name.."'s Stall"
			makestring()
			player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - stallprice.Value
			script.Parent.Parent.CurrentOwner.Value = player.Name
		end
	end	

end)