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

Spotlight returns nil inside a tool?

Asked by 3 years ago

Hi everyone,

The following script is a very long ended way of testing out properties in tools. I'm using a flashlight tool made by bugman1117. But that part may be irrelevant.

I can successfully detect and print the name of the player, character, flashlight in the backpack, flashlight in the workspace when activated ("FL"), and the LightPart ("LP) inside of the tool where the Spotlight is parented.

But trying to print the Spotlight name returns a nil. Is there a different property for lights than other parts for detecting them?

Thanks for your help!

Dubs

This is inside of ServerScriptService

local light
local char

game.Players.PlayerAdded:Connect(function(player)
    print(player.Name.." has joined the game")

    player.CharacterAdded:Connect(function(character)
        char = character
        print(character.Name.." has joined the game")

        local flashlight = player.Backpack:FindFirstChild("Flashlight")
        if flashlight then
            light = flashlight
            print("Found the light")
            print(light)
            if flashlight.Enabled then
                print("on")
            else
                print("off")
            end
        else
            print("Fail")
        end
    end)
end)

wait(10)
if light.Enabled then
    print("on")
else
    print("off")
end

wait(10)
if char then
    local FL = char:FindFirstChild("Flashlight")
    if FL then
        print("the light is in the world")
        local LP = FL:FindFirstChild("LightPart")
        if LP then
            print(LP)
            local SL = LP:FindFirstChild("Spotlight")
--SL prints nil even though the Spotlight part is a child of the LightPart????--
        print(SL)
        else
            print("light is not on")
        end
    else
        print("the light was not found")
    end
end

~~~~~~~~~~~~~~~~~

0
can u send a pic of inside the lightpart and if possible the whole flashlight in the explorer tab sne_123456 439 — 3y

1 answer

Log in to vote
0
Answered by
bnxDJ 57
3 years ago
Edited 3 years ago
            local SL = LP:FindFirstChild("SpotLight")-- You forgot the capital L

This should work.

0
Thank you. I hate when it's just a typo. Still can't get to the light attributes, but it's one step closer. thedubsgaming 22 — 3y
Ad

Answer this question