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

Problem with script not recognizing parts/image labels?

Asked by 7 years ago

I have a camera script that includes a local variable called "name". It looks for an text label called CamLabel, which is located in the parent of this script. When I go into Test Mode, everything is fine. Outside of Test Mode, line 2 seems to cause a problem where it thinks CamLabel is not a valid member of ImageLabel. There's a similar problem where it says the CamPos not valid member of Imagelabel

local Pos = script.Parent.Parent.CamPos
local name = script.Parent.Parent.camLabel

function onClicked()
    if Pos.Value == 1 then
    else
    script.Parent.Parent.Parent.Parent.Blip:Play()
    name.Text = "Party Room 1"
    Pos.Value = 1
    end
end
script.Parent.MouseButton1Down:connect(onClicked)

There's also the same problem where it thinks a part called Focus1 is not a valid member of Workspace, even though it's in workspace.

local Camera = game.Workspace.CurrentCamera
local Focus = Camera.Focus
local Character = game.Players.LocalPlayer.Character
local Subject = game.Workspace.Focus1
local angle = 0

function onClicked()
script.Parent.Parent.CameraInterface.Visible = true
script.Parent.Parent.Parent.CameraOn:Play()
script.Parent.Static.Disabled = false
script.Disabled = true
script.Parent.Off.Disabled = false
script.Parent.CameraStay.Disabled = false
script.Disabled = true
script.Parent.Off.Disabled = false
end
script.Parent.MouseButton1Down:connect(onClicked)

One: I have absolutely no idea why Test Mode doesn't show these problems. Two: I have absolutely no idea how to fix these problems. Any help?

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

This is due to the fact that not all objects are loaded immediately when the client joins the server. Y

ou can use the WaitForChild function to ensure that your script is yielding enough time for essential objects to load.

local Pos = script.Parent.Parent:WaitForChild("CamPos");
local name = script.Parent.Parent:WaitForChild("camLabel");

--Other script
local Subject = workspace:WaitForChild("Focus1");
Ad

Answer this question