This is going to be hard for me to explain but, the script I have bellow works, the only problem is that it starts to lag (Hard) the more you use it, and will eventually crash. It starts to lag because lines 4 & 5 start to stack up each time the function is fired, but I don't know how to turn them off... This is hard for me to explain but hopefully you guys can understand what I mean.

data = script.Parent.Parent.Parent.Parent.WatBox
local function update()
	if data~=nil then
		data.Value.Items.ChildAdded:connect(update)
		data.Value.Items:WaitForChild(script.Parent.Name).Changed:connect(update)
	end
	if data.Value~=nil and data.Value.Items:FindFirstChild(script.Parent.Name) and data.Value.Items[script.Parent.Name].Value == 0 then
		script.Parent.Visible = false
		elseif data.Value~=nil and data.Value.Items:FindFirstChild(script.Parent.Name) then
			script.Parent.Visible = true
			script.Parent.ItemCount.Value = data.Value.Items[script.Parent.Name].Value
			script.Parent.Weight.Value = data.Value.Items[script.Parent.Name].Value*game.Players.LocalPlayer.Inventory[script.Parent.Name].Weight.Value
		    script.Parent.Amount.Text = "x"..data.Value.Items[script.Parent.Name].Value
		else
		script.Parent.Visible = false
	end		
end
data.Changed:connect(update)
wait(0.1)
update()

3 comments

0

What is your script doing?

0

It's displaying the items in a chest

0

Anyone?