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
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
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)
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
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.
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.