Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Character light wont enable?

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 :)

2 comments

1

Put a print after line two, and say if it prints

0

No print, I suppose it's not finding the Character?

2 answers

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
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)


This discussion is preserved as it was. New answers, comments, and votes are closed.