Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Variable not updating why?

Asked by
qwrn12 85
8 years ago

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

Log in to vote
-2
Answered by 8 years ago

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

0
why does it need tostring qwrn12 85 — 8y
Ad
Log in to vote
2
Answered by
Legojoker 345 Moderation Voter
8 years ago

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)
0
it doesn't work qwrn12 85 — 8y

Answer this question