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

How would i make a flashlight's light connect to a torso?

Asked by 9 years ago

Im wondering how to make a light connect to a torso. And also activate it by touching F, can anyone help?

1
Do you want the flash light to be visible? Else you can just use a Spotlight. iNicklas 215 — 9y

2 answers

Log in to vote
1
Answered by
iNicklas 215 Moderation Voter
9 years ago
game.Players.PlayerAdded:connect(function(player) -- function for when they join
    player.CharacterAdded:connect(function(character) -- function for there characters path
        Instance.new("SpotLight",character.Torso) -- inserts spotlight instance
        character.Torso.SpotLight.Angle = 90
        character.Torso.SpotLight.Range = 16
        character.Torso.SpotLight.Color = Color3.new(255,255,255)
        character.Torso.SpotLight.Brightness = 14
    end)
end)

This will make all characters torso's a spotlight, you can change the numbers if ya like.

0
ummm, Player and Character added are events, not functions. EzraNehemiah_TF2 3552 — 9y
0
Ohhhhhh, my gawd. sorry :( iNicklas 215 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Just to add on the iNicklas' answer. If you want it to activate by pressing F, you can have a separate LocalScript in StarterPack and use the following script:

local player = game.Players.LocalPlayer --You can access the LocalPlayer when using LocalScripts.
local char = player.Character or player.CharacterAdded:wait() --Either uses the player's character or waits until it is added.
local db = false --Debounce, used to add a delay to functions.

game:GetService("UserInputService").InputChanged:connect(function(input) --When the input from the player to the game is changed. E.G: Keystroke, button press, etc.
    if db then return end --If db is true, stop the function.
    db = true --Sets db to true so only the current function runs.
    if input.KeyCode == Enum.KeyCode.F then --If the F key is pressed.
        local spot = char.Torso:FindFirstChild("SpotLight")
        if spot == nil then return end
        spot.Enabled = not spot.Enabled
        wait(.5) --Waits for half a second, change .5 to something else if you want a longer/shorter wait time.
        db = false --Re enables the F key function after the time has elapsed.
    end
end)
0
I tried to put this on LocalScript and then put it on StarterPack, but it didn't work when I hit F RobotChitti 167 — 9y
0
Do you have a SpotLight in the Torso already? Spongocardo 1991 — 9y

Answer this question