So i want to make a simple tycoon game so i can learn more about scripting, but i’ve encountered a problem with the dropper system. To put you in perspective i want to start making the dropper do its stuff when it’s bought and i try to do that using a attribute called “IsBought” that will be true when the button gets bought and it actually sets to true, but the dropper doesn’t start dropping the parts as i want it to.
local CollectionService = game:GetService("CollectionService")
local Tag = CollectionService:GetTagged("Dropper")
for _, dropper in pairs(Tag) do
if dropper:GetAttribute("IsBought") == true then
repeat wait(2)
local product = Instance.new("Part")
product.Size = Vector3.new(1,1,1)
product.CFrame = dropper.NewPartPos.CFrame
product.Anchored = false
until false
end
end
When exactly does that code snippet run? It seems to make sense why it’s not working, as it looks like it only runs once, sees that the dropper isn’t bought, and then does nothing. You could use GetAttributeChangedSignal to detect when the IsBought attribute changes, and THEN run the loop to begin dropping the thingies.
I don’t know if i actually implented it right, but it seems like it doesn’t work.
local CollectionService = game:GetService("CollectionService")
local Tag = CollectionService:GetTagged("Dropper")
for _, dropper in pairs(Tag) do
if dropper:GetAttributeChangedSignal("IsBought") == true then
repeat wait(2)
local product = Instance.new("Part")
product.Size = Vector3.new(1,1,1)
product.CFrame = dropper.NewPartPos.CFrame
product.Anchored = false
until false
end
end
Hmm it seems like it still doesn’t work. I even tried to set the parent to workspace just in case the parts are getting spawned inside server storage, but still nothing.
Weird. Can I see your code that sets the attribute? Also, I made a typo. For the second one, I meant dropper:GetAttributeChangedSignal("IsBought"):Connect(function() instead of if dropper:GetAttributeChangedSignal("IsBought") == true then.
It might be a little messy, but please consider i’m a begginer.
for _,button in pairs(ButtonTag) do
if button:IsA("Model") then
local objectName = button.ObjectName.ObjectName
local objectPrice = button.ObjectPrice.Price
local price = button.Price
objectPrice.Text = price.Value.."$"
objectName.Text = button.Name
button.Main.Touched:Connect(function(hit)
local buttonId = button:GetAttribute("Id")
print(buttonId)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.Name == owner.Value and player.leaderstats.Cash.Value >= price.Value then
for _, newButton in pairs(ServerStorage.Buttons:GetChildren()) do
if newButton:GetAttribute("Id") == buttonId + 1 then
local newClonedButton = newButton
newClonedButton.Parent = button.Parent
print(newButton.Name.." appeared")
end
end
task.wait(0.05)
local object = ServerStorage.Builds:WaitForChild(button.Name):Clone()
object.Parent = button.Parent
button:Destroy()
script.Pop:Play()
player.leaderstats.Cash.Value -= price.Value
print(object.Name.." was bought")
if object.Name == "Dropper1" then
object:SetAttribute("IsBought", true)
end
------------------------------------------------------------------
else
print(player.Name.." is not the owner or not enough cash")
end
end
end)
end
end
Alright, I’m going to make a modification to the code snippet I sent earlier.
if dropper:GetAttribute("IsBought") == nil then
dropper:SetAttribute("IsBought") = false
dropper:GetAttributeChangedSignal("IsBought"):Connect(function()
if dropper["IsBought"] == true then
-- loop goes here
end
end)
Let me know if that changes anything. Also, are there any errors in output?