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

TweenService:Create failed because Instance is null? Error applies to Line 15

Asked by 5 years ago
local Water1 = script.Parent._Water1 
local Water2 = script.Parent._Water2
local Water3 = script.Parent._Water3
local Water4 = script.Parent._Water4

local TweenService = game:GetService("TweenService")

local Beam1 = Water3.Beam
local Beam2 = Water4.Beam

local NumberValue_A = Beam1:FindFirstChild("NumberValue")
local NumberValue_B = Beam2:FindFirstChild("NumberValue")

local LavaTween_A = TweenService:Create(NumberValue_A, TweenInfo.new(1), {["Value"] = 0.2})
local LavaTween_B = TweenService:Create(NumberValue_B, TweenInfo.new(1), {["Value"] = 0.2})

NumberValue_A:GetPropertyChangedSignal("Value"):connect(function()
    Beam1.Transparency = NumberSequence.new(NumberValue_A.Value)
end)

NumberValue_B:GetPropertyChangedSignal("Value"):connect(function()
    Beam2.Transparency = NumberSequence.new(NumberValue_B.Value)
end)

local Neon = Enum.Material.Neon
local Material_1 = Water3.Material 
local Material_2 = Water4.Material 

local SurfaceGlowA = Instance.new("SurfaceLight", Water3)
local SurfaceGlowB = Instance.new("SurfaceLight", Water4)

local Light_Face1 = Water3.SurfaceLight
local Light_Face2 = Water4.SurfaceLight

LavaState_Water3 = function()
    LavaTween_A:Play()
    Material_1 = Neon
    print(SurfaceGlowA)
    Light_Face1.Face = "Top"
    Light_Face1.Color = Color3.new(255, 0, 0)
end

LavaState_Water4 = function()
    LavaTween_B:Play()
    Material_2 = Neon
    print(SurfaceGlowB)
    Light_Face2.Face = "Top"
    Light_Face2.Color = Color3.new(255, 0, 0)
end





wait(5)
Water1:Destroy()
Water2:Destroy()
wait(2)

LavaState_Water3()
wait(3)
LavaState_Water4()

1
WaitForChild is your best friend. Fifkee 2017 — 5y
0
I believe this is saying that whatever NumberValue_B is, is nil i.e it can't find it in the explorer hierarchy MachoPiggies 526 — 5y
0
@Fifkee Where would I type that? I'm still a little confused. ThaDogeTho 11 — 5y

1 answer

Log in to vote
1
Answered by
Psudar 882 Moderation Voter
5 years ago
Edited 5 years ago

Assuming these number values actually have been inserted in your game, it appears to be indexing them before they're loaded in.

Basically, you can use the :WaitForChild() function to ensure that the script halts until that object is found.

Pretty much every roblox object has this function, use it to your advantage.

:FindFirstChild(), however; Doesn't halt. That means that if the object you're trying to index is nil (not loaded in) , it's going to return nil.

You should be able to solve it likes this:

local NumberValue_A = Beam1:WaitForChild("NumberValue")
local NumberValue_B = Beam2:WaitForChild("NumberValue")

Now whenever you create the new tween, in theory; it should work.

If the error persists, make sure you check your spelling. You may have a typo.

0
Oh and uh you may assume im implying that `nil` means not loaded in, it doesnt mean that. It simply means no value or absence of a value Psudar 882 — 5y
Ad

Answer this question