It messes up the same ones most of the time, I tested it 5 times and once it changed which weapons had which value
In this case I would recommend looking at the price values in the weapons. To make sure they are not the same/duplicated.
I just checked and each are different
And your sure you have no other scripts changing the prices or are getting errors in the output?
I have found the error. You had a duplicate variable of objectPrice.
Only other script is the buy script but that does not mention the Price value at all
I think I have fixed the error. If it still occurs please tell me.
local folder = game.ReplicatedStorage:WaitForChild("Tools")
local frame = script.Parent:WaitForChild("ScrollingFrame")
local template = frame.Template
local shopButton = script.Parent:WaitForChild("ShopButton")
for _, tool in pairs(folder:GetChildren()) do
local newTemplate = template:Clone()
newTemplate.Name = tool.Name
newTemplate.ObjectName.Text = tool.Name
newTemplate.Visible = true
newTemplate.Parent = frame
local objectPrice = template.ObjectPrice
objectPrice.Text = tool.Price.Value
local object = tool:Clone()
object.Parent = newTemplate.ViewportFrame
local camera = Instance.new("Camera")
camera.CFrame = CFrame.new(object.Handle.Position + (object.Handle.CFrame.lookVector*5)+ Vector3.new(2,2,2),object.Handle.Position)
camera.Parent = newTemplate.ViewportFrame
newTemplate.ViewportFrame.CurrentCamera = camera
newTemplate.MouseButton1Click:Connect(function()
local result = game.ReplicatedStorage.BuyItem:InvokeServer(tool.Name)
if result == true then
newTemplate.BackgroundColor3 = Color3.new(0.00392157, 1, 0.0352941)
else
newTemplate.BackgroundColor3 = Color3.new(0.92549, 0, 0)
end
wait(1)
newTemplate.BackgroundColor3 = Color3.new(1, 1, 1)
end)
end
shopButton.MouseButton1Click:Connect(function()
frame.Visible = not frame.Visible
end)
It still does not work, I just fixed it and the values still get messed up.
Wait, I am sorry but I think this should fix it I was looking at the wrong thing at found something else.
When calling the object price you were using the uncloned/base template frame instead of the new one.
local folder = game.ReplicatedStorage:WaitForChild("Tools")
local frame = script.Parent:WaitForChild("ScrollingFrame")
local template = frame.Template
local shopButton = script.Parent:WaitForChild("ShopButton")
for _, tool in pairs(folder:GetChildren()) do
local newTemplate = template:Clone()
newTemplate.Name = tool.Name
newTemplate.ObjectName.Text = tool.Name
newTemplate.Visible = true
newTemplate.Parent = frame
local objectPrice = newTemplate.ObjectPrice
objectPrice.Text = tool.Price.Value
local object = tool:Clone()
object.Parent = newTemplate.ViewportFrame
local camera = Instance.new("Camera")
camera.CFrame = CFrame.new(object.Handle.Position + (object.Handle.CFrame.lookVector*5)+ Vector3.new(2,2,2),object.Handle.Position)
camera.Parent = newTemplate.ViewportFrame
newTemplate.ViewportFrame.CurrentCamera = camera
newTemplate.MouseButton1Click:Connect(function()
local result = game.ReplicatedStorage.BuyItem:InvokeServer(tool.Name)
if result == true then
newTemplate.BackgroundColor3 = Color3.new(0.00392157, 1, 0.0352941)
else
newTemplate.BackgroundColor3 = Color3.new(0.92549, 0, 0)
end
wait(1)
newTemplate.BackgroundColor3 = Color3.new(1, 1, 1)
end)
end
shopButton.MouseButton1Click:Connect(function()
frame.Visible = not frame.Visible
end)
That did it in! Woo Thank you and this time it looks like everything is working
Also just marked it as solution
np and thank you! If you have any more questions feel free to ask!