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

Character light wont enable?

Asked by 8 years ago

I have this script, well it's a LocalScript. It is in a GUI where it should toggle a PointLight I have placed in the characters torso to Enable and Disable but it does nothing. Like just nothing happens and no output errors either I'm lost, any help?

local player = game.Players.LocalPlayer
local char = player:WaitForChild("Character")
local but = script.Parent
local light = Instance.new("PointLight", char.UpperTorso)
local ison = but.ison

ison.Value = false
light.Name = "Charlight"
light.Enabled = false
light.Range = 12
light.Brightness = 1.5

but.MouseButton1Down:connect(function()
    if ison.Value == false then
        light.Enabled = true
        ison.Value = true
    elseif ison.Value == true then
        light.Enabled = false
        ison.Value = false
    end
end)

Any help is appreciated :)

1
Put a print after line two, and say if it prints theCJarmy7 1293 — 8y
0
No print, I suppose it's not finding the Character? CrispyBrix 113 — 8y

2 answers

Log in to vote
1
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

Your problem is that the function WaitForChild will yield the script until a child of the particular object is added with the given name. The Character I assume you are referring to is not a child of the player object, but rather a property.

To wait until the character is loaded, you could do something like this (assuming variable player is defined):

if not player.Character then
    player.CharacterAdded:wait()
end
local character = player.Character
Ad
Log in to vote
0
Answered by 7 years ago
function onRespawn(Character)
    if (Character:findFirstChild("Torso") ~= nil) then
        light = Instance.new("PointLight")
        light.Parent = Character.Torso
        light.Range = 12
    end
    if (Character:findFirstChild("Torso") == nil) then
    end 
end
game.Workspace.ChildAdded:connect(onRespawn)



game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        player.Character.Humanoid.JumpPower = 0
    end)
end)


Answer this question