How do I make a light follow a player

I need help with my code I don’t know how to fix this I’m new to scripting and I’m trying to make a light follow the player

  1. What do you want to achieve? I want to make a light follow the player

  2. What is the issue? I don’t know what is wrong with my code I couldn’t upload the video it was stuck at 86%

  3. What solutions have you tried so far? I looked for posts about this on the devforum but couldn’t find any

local light = script.SpotLight
local player = game:GetService("Players").LocalPlayer
local aaa light:Clone(player.Head)

if aaa.Parent = Head then
	print("test")
end

I am just going to do something else because I found an easier way to do it but thanks Kaid3n22 for helping

2 Likes

2 errors here.

  1. it should be local aaa =
  2. head is not a child of player. it is a child of player.Character. Also, parenting it would be on a different line.
local light = script.SpotLight
local player = game:GetService("Players").LocalPlayer
player.CharacterAdded:Connect(function(char)
	local aaa = light:Clone()
	aaa.Parent = char.Head

	if aaa.Parent = char.Head then
		print("test")
	end
end)

Also, put this in a CharacterAdded function so it will do it when the player spawns.

2 Likes

you must put a spawn and deny the cancollide and transparency remove the decal and put a script


and then in the script you put this:

script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild(“Humanoid”) then
light = Instance.new(‘PointLight’)
light.Parent = Hit.Parent.Head
end
end)


And if it’s horror like a story, you put it to teleport the players to spawn and that’s it
Good luck

This is not very correct to do.

why not? it works what is the problem?

Whenever the player touched the spawner a new light would be added to it, ie a bunch of instances would be created, resulting in lag

2 Likes

read these articles:

https://developer.roblox.com/en-us/api-reference/property/Player/Character

When you finish reading everything, you will have already learned how to make this script.
Note: you don’t need to read everything

1 Like