Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I run this when the player joins the game OR gets a new item?

So, I've tried multiple ways of doing this, but it normally just overlaps or duplicates the previous items, so how can I run this when a player either joins, or gains an item (plr:WaitForChild("Inventory").ChildAdded)

local fram = script.Parent.back
local plr = script.Parent.Parent.Parent
function UpdateOldLabels(Parent)	
	for i,v in pairs(Parent:GetChildren()) do
		if v.Name:sub(1,4):lower() == "item" then
			local LineNumber = v.Name:sub(5)
			v.Name = "item"..tostring(tonumber(LineNumber) + 1)
			v.Position = v.Position + UDim2.new(0.02,0,0,0)
		end
	end
end

for _,v in pairs(plr:WaitForChild("Inventory"):GetChildren()) do
	local item = Instance.new("ImageButton", fram)
	item.BackgroundTransparency = 1
	item.Name = "item1"
	item.Size = UDim2.new(.02, 0, .6, 0)
	item.Position = UDim2.new(-.02, 0, 0.15, 0)
	item.Image = "rbxassetid://"..tostring(v.itemPrev.Value)
	item.ZIndex = 2
	UpdateOldLabels(fram)
end

1 answer

I believe it may be if game.Players.PlayerAdded then end

1 comment

0

nope, you are missing the connect part. Specificly in roblox, a connect to an event is required to handle the event. the connect function requires a function as parameter, so an example is game.Players.PlayerAdded:connect()

This discussion is preserved as it was. New answers, comments, and votes are closed.