Hello! I have come across yet another issue with my system!
This time it is in relation to changing a value back to its empty state. Every single time I attempt to change it from “YouJustGotShahBanged” back to just “” it wants to give me Attempt To Index Nil With Value.
This is really frustrating as the code makes sense yet it seems to think that the variable Target does not have a value inside. Screenshots below.
local wp = game.Workspace:GetChildren()
local target = nil
for i, v in pairs(wp) do
if v:IsA("StringValue") and v.Value == (script.Parent.Parent.Parent.Parent.Parent.Parent.Name) then
target = v
end
end
if target then
target.Value = nil
end
script.Parent.Parent:Destroy()
end)
No, when you do that if statement, it checks both at the same time. So since that the child does not have a property called value, it will return an error. So you should check if it is a string value, before checking the value of the string
local wp = game.Workspace:GetChildren()
local target = nil
for i, v in pairs(wp) do
if v:IsA("StringValue") then
if v.Value == script.Parent.Parent.Parent.Parent.Parent.Parent.Name then
target = v
end
end
end
target.Value = ""
print(target)
script.Parent.Parent:Destroy()
end)
Nope it still says that the target.value = “” is wrong unfortunately.
Have renamed it to “Person” and can confirm that it has made no difference.
Reverted the script back to original and it tells me the error is on Line 12 (target.Value = "").
Edit: This is the code, I only took away the if target ~= nil.
local wp = game.Workspace:GetChildren()
local target = nil
for i, v in pairs(wp) do
if v:IsA("StringValue") then
if v.Value == script.Parent.Parent.Parent.Parent.Parent.Parent.Name then
target = v
end
end
end
target.Value = ""
script.Parent.Parent:Destroy()
end)
RGui is short for “RetrieveGui”. This is for closing the gui. Once closed it will remove all the variables that state who is using the gui and puts it back into its unused state so that the next person can use it and their name can be stored.
This means that in the in pairs loop, the value of target is not being set. You can then conclude that one of the conditionals in the in pairs loop is never true and thus the value of target is never set to v. Please recheck all your conditions and make sure you’re not making any mistakes. As @TwyPlasma and @ZombieCrunchUK suggested, consider changing the ValueObject’s name to something other than Name. You should generally avoid changing instance’s name to Name as the script thinks you’re referencing the Name of the instance you previously referenced. Could you please elaborate on what this returns: script.Parent.Parent.Parent.Parent.Parent.Parent.Name.
I tested your code and it works fine here. The only things I changed was the value test and the bit at the bottom which destroys a script.
local wp = game.Workspace:GetChildren()
local target = nil
for i, v in pairs(wp) do
if v:IsA("StringValue") then
if v.Value == "hello" then
target = v
end
end
end
target.Value = ""
print(target)