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

Variable not updating why?

the variable Framee is not is not updating and i don't know why can you please help me here is code

player.Backpack.ChildAdded:connect(function(instance)
	local name=instance.Name
	if name==game.Lighting.E:GetChildren()[1].Name or name==game.Lighting.Q:GetChildren()[1].Name or name==game.Lighting.R:GetChildren()[1].Name or name==game.Lighting.F:GetChildren()[1].Name or name==game.Lighting.G:GetChildren()[1].Name then
		print(instance.Name .. " added to the backpack by item Clone")
	else
    	print(instance.Name .. " " .. Framee)
		player.PlayerGui.Invintory[Framee].Frame1.Visible = true
		local FrameNumber = FrameNumber + 1
		local Framee = "Frame" .. FrameNumber
	end
end)

can anyone tell my why

2 answers

✓ Accepted answer

The string change on line 9 requires a tostring() statement: Framee="Frame"..tostring(FrameNumber) Hope this helped!

1 comment

0

why does it need tostring

local Framee = "Frame" .. FrameNumber is only updating for that specific function run through. This essentially means that the variable is worthless since it is defined and then forgotten as it is enclosed inside the function. This is the same for FrameNumber. To make it a variable seen by the entire script, predefine it outside of the function like this:

local FrameNumber = 0
local Framee = "Frame"..FrameNumber

player.Backpack.ChildAdded:connect(function(instance)
	local name=instance.Name
	if name==game.Lighting.E:GetChildren()[1].Name or name==game.Lighting.Q:GetChildren()[1].Name or name==game.Lighting.R:GetChildren()[1].Name or name==game.Lighting.F:GetChildren()[1].Name or name==game.Lighting.G:GetChildren()[1].Name then
		print(instance.Name .. " added to the backpack by item Clone")
	else
		print(instance.Name .. " " .. Framee)
		player.PlayerGui.Invintory[Framee].Frame1.Visible = true
		FrameNumber = FrameNumber + 1
		Framee = "Frame" .. FrameNumber
	end
end)

1 comment

0

it doesn't work

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