I have a placement system for a defending base game. Players have a shop GUI to buy things to defend like parts and fences. There is a problem, though. When you click the item, it registers that you bought the product and puts it in the Workspace. But it goes off the screen and you can only see it for a split second before the product disappears. This program has NO errors, just my error ????
You can find the object tree here.
Here is the code so far:
for i,v in pairs(script.Parent:GetChildren()) do if v.ClassName == "Frame" then v:FindFirstChildWhichIsA("ImageButton").MouseButton1Up:connect(function() if script.Parent.Parent.Parent.Parent.leaderstats.Money.Value > tonumber(string.sub(v.PriceLabel.Text, 2, string.len(v.PriceLabel.Text))) then local clone = game.ServerStorage[v:FindFirstChildWhichIsA("ImageButton").Name]:Clone() clone.Parent = game.Workspace local highlight = Instance.new("SelectionBox") highlight.Parent = clone highlight.Color3 = Color3.new(0, 255, 0) local mouse = script.Parent.Parent.Parent.Parent:GetMouse() while wait() do clone:MoveTo(Vector3.new(math.floor(mouse.X), 3, mouse.Y)) end -- Also I need more code to detect when the player clicks, it places the item down and takes money away. That would go here. script.Parent.Parent.Parent.Parent.leaderstats.Money.Value = script.Parent.Parent.Parent.Parent.leaderstats.Money.Value - tonumber(string.sub(v.PriceLabel.Text, 2, string.len(v.PriceLabel.Text))) end end) end end
I know this might not be the best way to accomplish this (I have not done this before!), but can anyone help me?
Thanks!
EDIT 1
Please paste the code into a code text editor if you have one, as this site cannot fit the long lines of code.
EDIT 2
Here is a simplified version with variables. You might still need to use the "view source" option to read the code better.
for i,v in pairs(script.Parent:GetChildren()) do if v.ClassName == "Frame" then v:FindFirstChildWhichIsA("ImageButton").MouseButton1Up:connect(function() local money = script.Parent.Parent.Parent.Parent.leaderstats.Money local price = tonumber(string.sub(v.PriceLabel.Text, 2, string.len(v.PriceLabel.Text))) if money.Value >= price then local clone = game.ServerStorage[v:FindFirstChildWhichIsA("ImageButton").Name]:Clone() clone.Parent = game.Workspace local highlight = Instance.new("SelectionBox") highlight.Parent = clone highlight.Color3 = Color3.new(0, 255, 0) local mouse = script.Parent.Parent.Parent.Parent:GetMouse() while wait() do clone:MoveTo(Vector3.new(math.floor(mouse.X), 3, mouse.Y)) end -- Also I need more code to detect when the player clicks, it places the item down and takes money away. That would go here. money.Value = money.Value - price end end) end end