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

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

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

1 comment

1

Do you want the flash light to be visible? Else you can just use a Spotlight.

2 answers

✓ Accepted answer
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.

2 comments

0

ummm, Player and Character added are events, not functions.

0

Ohhhhhh, my gawd. sorry :(

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)

2 comments

0

I tried to put this on LocalScript and then put it on StarterPack, but it didn't work when I hit F

0

Do you have a SpotLight in the Torso already?

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