Tycoon make it so only the owner can buy button (help)

Hi,

I added a feature where if the player has enough money they can buy a tycoon button, but it’s not linked to the plot owner.

I want only the owner of that plot to be able to purchase their own buttons.

local ServerStorage = game:GetService("ServerStorage")


local Buttons = script.Parent.Buttons
local Purchases = script.Parent.Purchases


local StoredPurchases = Instance.new("Folder")
StoredPurchases.Name = "Purchases"
StoredPurchases.Parent = ServerStorage

for i,v in pairs(Purchases:GetChildren()) do
    v.Parent = StoredPurchases
end

for i,v in pairs(Buttons:GetChildren()) do
    local Price = v:WaitForChild("Price").Value
    local Object = v:WaitForChild("Object").Value
    local PurchasePrompt = v:WaitForChild("Purchase")



    PurchasePrompt.Triggered:Connect(function(player)
        if Price <= player.leaderstats.Money.Value then
            player.leaderstats.Money.Value -= Price
            local PurchasedObject = Object:Clone()
            PurchasedObject.Parent = Purchases
            Object:Destroy()
            v:Destroy()
        else
            warn("Not enough money!")
        end
    end)
end
1 Like

I forgot to mention. I do have a plot system, a plot that is assigned to the player when they join which is here.

image

You could add in a string value whenever a player buys the tycoon that contains it’s name then whenever it’s triggered go to that tycoon get the name and check if it is the player that triggered it’s name

1 Like

You need to check if the “player” in your Triggered function is equal to the owner value.

PurchasePrompt.Triggered:Connect(function(player)
    if player == plot.plr.Value then
        --Buy it
        if Price <= player.leaderstats.Money.Value then
              player.leaderstats.Money.Value -= Price
              local PurchasedObject = Object:Clone()
              PurchasedObject.Parent = Purchases
              Object:Destroy()
              v:Destroy()
        else
              warn("Not enough money!")
        end
    else
        print("Wrong player!")
    end
end)

And your value is a string value!

1 Like

Every plot has their own assigned owner which has their own stringvalue called “plr”. How do I call it in the script to check?

Thanks! :smiley: but how do I put that into my script, because the if value checks if the player has enough money.

I imagine I have to implement your code into this part? but how?



	PurchasePrompt.Triggered:Connect(function(player)
		if Price <= player.leaderstats.Money.Value then
			player.leaderstats.Money.Value -= Price
			local PurchasedObject = Object:Clone()
			PurchasedObject.Parent = Purchases
			Object:Destroy()
			v:Destroy()
		else
			warn("Not enough money!")
		end
	end)
end

I editted my post, check it out.

1 Like

Thanks! I do get this error, though.

image

image

your plot is undefined so try getting it

Well you do have to set the “plot” variable to the actual plot, right now “plot” is undefined.
You’ll need to set that yourself since I don’t know where your “purchased object” is in relation to the plot.

Okay, I’ll try to define it! :slight_smile:

I do get this error thought. I believe it may be a syntax error as I did define my plot.

image

maybe try setting the player to player.Name

Is there an “end” missing just under where the image ends?

no all ‘ends’ are there i think

1 Like

nope, no other ends, that was it. just two

Actually what about the one after the end) for the pairs loop

Yea I think there should be another one after, that’s what I meant with “missing”.

Also if your “plr” value is a string value holding the player’s name, you should (as Dv_WedDev said) check if plot1.plr.Value == player.Name, and not just if plot1.plr.Value == player.

Sorry, I’m fairly beginner at lua. How do I do that? I tried adding another end, but still nothing.