Trying to make the elseif part of the script work, but it doesn’t for some reason. Tried playing around with the code and look through the forums but nothing worked hence I’m here.
--local player = game.Players.LocalPlayer
local framevaluef = script.Parent.FrameValues
for _, descendant in pairs(framevaluef:GetChildren()) do
if descendant:IsA("ObjectValue") then
descendant.Changed:Connect(function()
for _, child in pairs(script.Parent:GetChildren()) do
if child:IsA("Frame") then
if child.Name == descendant.Name and descendant.Value ~= nil then
child.ImageButton.CharacterDisplay.DisplayScript.Enabled = false
child.ImageButton.CharacterDisplay.Shotgun:Destroy()
local car = descendant.Value:Clone()
car.Parent = child.ImageButton.CharacterDisplay
car.Name = "Shotgun"
task.wait()
child.ImageButton.CharacterDisplay.DisplayScript.Enabled = true
elseif child.Name == descendant.Name and descendant.Value == nil then
child.Visible = false
print("setting them to invisible")
end
end
end
end)
end
end
--local player = game.Players.LocalPlayer
local framevaluef = script.Parent.FrameValues
for _, descendant in pairs(framevaluef:GetChildren()) do
if descendant:IsA("ObjectValue") then
descendant.Changed:Connect(function()
for _, child in pairs(script.Parent:GetChildren()) do
if child:IsA("Frame") then
print("DEBUG child NAME: ", child.Name)
print("DEBUG descendant NAME: ", descendant.Name)
print("DEBUG descendant value", descendant.Value)
if child.Name == descendant.Name and descendant.Value ~= nil then
child.ImageButton.CharacterDisplay.DisplayScript.Enabled = false
child.ImageButton.CharacterDisplay.Shotgun:Destroy()
local car = descendant.Value:Clone()
car.Parent = child.ImageButton.CharacterDisplay
car.Name = "Shotgun"
task.wait()
child.ImageButton.CharacterDisplay.DisplayScript.Enabled = true
elseif child.Name == descendant.Name and descendant.Value == nil then
child.Visible = false
print("setting them to invisible")
end
end
end
end)
end
end
This will help you see what is being printed. Make sure your names are exact for exact or else it wont work
Here, I cleaned it up with some guard clauses. You also do not need to check if a variable is equal to nil, you just need to check for the variable itself.
For example, someVariable in a boolean expression reduces to true if it exists, and false if it does not exist (is equal to nil)
for _, descendant in pairs(framevaluef:GetDescendants()) do
if not descendant:IsA("ObjectValue") then continue end
descendant.Changed:Connect(function()
for _, child in pairs(script.Parent:GetChildren()) do
if not child:IsA("Frame") then continue end
if child.Name ~= descendant.Name then continue end
if descendant.Value then
child.ImageButton.CharacterDisplay.DisplayScript.Enabled = false
child.ImageButton.CharacterDisplay.Shotgun:Destroy()
local car = descendant.Value:Clone()
car.Parent = child.ImageButton.CharacterDisplay
car.Name = "Shotgun"
task.wait()
child.ImageButton.CharacterDisplay.DisplayScript.Enabled = true
else
child.Visible = false
print("setting them to invisible")
end
end
end)
end
This did help and I think I know what the issue is. Its descendant.Changed. The ones that are nil don’t really ever change, they are always nil. So now I need to figure a way to make them change and then change back to nil.
Glad to see you are able to narrow it down. If you still cant come up with a solution, you could supply us your other code function where you set them to nil?