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

How do I produce light around Character Torso on Click?

Asked by 7 years ago
Edited 7 years ago

So there's this part called "LightSource". When you click it, it disappears and produces light around the torso of the character that is clicking it. This script didn't work:

local Player = game.Players.LocalPlayer
local LightSource = game.Workspace.LightSource
local Mouse=Player:GetMouse()
Mouse.Button1Down:connect(function()
    if Mouse.Target and Mouse.Target.Name == 'LightSource' then
        if (Player:findFirstChild("Torso") ~= nil) then
            local light = Instance.new("PointLight")
            light.Parent = Player
            light.Range = 15
        end
        if (Player:findFirstChild("Torso") == nil) then
        end
        LightSource:Remove()
    end
end)
0
Use the code block, please. alonzo12345 60 — 7y

1 answer

Log in to vote
0
Answered by
Troidit 253 Moderation Voter
7 years ago
Edited 7 years ago

Your problem appears to be that you're trying to grab the player themselves instead of their character. When you acquire LocalPlayer, you're getting their information for Players which isn't where their character will be. That can be found in the Workspace as a model named the same as the player.

I know what you're thinking, but instead of finding them via game.Workspace, you can locate their character with game.Players.LocalPlayer.Character

local Player = game.Players.LocalPlayer
local Character = Player.Character -- This should allow for you to locate the actual character to the player.
local LightSource = game.Workspace.LightSource
local Mouse=Player:GetMouse()

Mouse.Button1Down:connect(function()
    if Mouse.Target and Mouse.Target.Name == 'LightSource' then
        if (Character:findFirstChild("Torso") ~= nil) then
            local light = Instance.new("PointLight")
            light.Parent = Character
            light.Range = 15
        end
        if (Character:findFirstChild("Torso") == nil) then
        end
        LightSource:Remove()
    end
end)

I'm not able to test the script right now, but I assume it works?

Side note: In the future, you can block lines of code like I did in the text editor by highlighting the text and clicking the little Lua symbol at the top of the text box.

0
What is this "LUA" you speak of? What does it stand for? Also, I'd recommend handling this through clickdetectors rather than the player mouse. systack 123 — 7y
0
Sorry for not using the code block. I'm new. Also, I noticed that there is no "Torso" in R15 rigs. So I replaced it to "HumanoidRootPart". It still doesn't light up. EzraNewLight 6 — 7y
0
I also tried "LowerTorso" since it's from an R15 rig, it still doesn't work EzraNewLight 6 — 7y
0
I'm honestly not sure then. I haven't done much work with R15, I assumed since you were acquiring "Torso" that you were working with the previous version. Troidit 253 — 7y
Ad

Answer this question