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

script keeps returning nil even if the specified value exists?

Asked by 5 years ago
wait(0.5)
local char = script.Parent
local oldval = game.ReplicatedStorage:FindFirstChild("TpVal"..char.Name)



if oldval ~= nil then
    print("not nil")
    script.Parent.RestorePlrHomePos.Disabled = false
    wait(0.1)
    script.Parent.TpPosServerSync.Disabled = false
    wait()
    script.Disabled = true
end


if oldval == nil then
    print("nil")
    local tpval = Instance.new("Vector3Value")
tpval.Name = "HomeTp:"..char.Name
tpval.Parent = game.ReplicatedStorage
script.Parent.TpPosServerSync.Disabled = false
wait()
script.Disabled = true
end

here is my problem: this script first checks in replicatedstorage for a value with "TpVal (characters name)" if its not there it runs the bottom portion of the script, if it is there then it runs the upper portion. the problem is even if the value IS there it always returns nil rather than not nil.

0
instead of two if statements try that first if statements followed by an elseif DeceptiveCaster 3761 — 5y
0
statement* DeceptiveCaster 3761 — 5y
0
it still returned nil regardless of there being a value in replicatedstorage. mantorok4866 201 — 5y
0
Try extending the wait, it could be that it just doesnt exist yet. You sadly cant use waitforchild since thats the entire point of the code. DinozCreates 1070 — 5y

Answer this question