Shop Gui Button not Giving Players Tools

So, I made a script (with help from youtube tutorials, like @Alvin_Blox’s) that gives players tools when purchased a tool. It was doing well a few months ago then suddenly, it stopped working properly today. So yeah, every time I click my buy button, it doesn’t give me items.
Here’s the script(Please tell me if I made some mistakes here.):



local folder = game.ReplicatedStorage:WaitForChild("Tools")

local frame = script.Parent:WaitForChild("Frame")

local template = frame:WaitForChild("Template")

local button = script.Parent:WaitForChild("Button")

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 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(1,2,1),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.fromRGB(116, 255, 92)
		else
			
			newTemplate.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
		end
		
		wait(1)
		
		newTemplate.BackgroundColor3 = Color3.fromRGB(188, 255, 110)
	end)
end



button.MouseButton1Click:Connect(function()
	frame.Visible = not frame.Visible
	script.Parent.Header.Visible = not script.Parent.Header.Visible
end)

Screenshot of the Gui (could help you):
image

Can you please elaborate more, any errors etc.?

1 Like

When I play the game, it says that there’s something wrong at line 30, but it kind of seem like nothing’s wrong with it. I am not entirely sure if it is wrong though.

Whats line 30, can you send the error context?

1 Like

Here’s line 30:
image
Then here’s the error:
image

It looks like theres a problem inside the script the local script invoked. Could you show me the script that it tryed to invoke in?

1 Like

I think so. The script is in my main post (if it is the one you are referring to.).

The script i am referring to is where your purchases get handled on the server

BuyItem.OnServerInvoke:Connect(function() etc thats where im referring to.

1 Like

Oh okay, sorry for that lol. The script is referring to this, probably:
image

1 Like

Yes your right. Theres something wrong in that script. But you should be available to see what the error is when you test.

1 Like