Hi all, how would I attach a Spotlight to a player when they collide with a brick? I also want it to disappear after 10 seconds.
I think this is just a basic example of something like what you’re trying to achieve:
local Part, Players = script.Parent, game:GetService('Players')
Part.Touched:Connect(function(TouchingPart)
if (Players:GetPlayerFromCharacter(TouchingPart.Parent)) then
local Light = Instance.new('SpotLight')
Light.Brightness = 1
-- Set other properties
Light.Parent = TouchingPart.Parent.HumanoidRootPart
wait(10)
Light:Destroy()
end
end)
You may also need to add a debouce if it fires multiple times.
Edit: whoops. Forgot about destroying it after 10 seconds lol
Part.Touched:connect(function(Hit)
if Hit.Parent:FindFirstChild("Humanoid") then
local SpotLight = Instance.new("SpotLight",Hit.Parent.Head);
game:GetService("Debris"):AddItem(SpotLight,10);
end
end)
As a rule this a “Scripting Support” forum. Please atleast make some sort of attempt to solve your problems before coming here. There are plenty of free models as well as wiki pages that would of helped you figure this out.
3 Likes
You’d also probably want to use either Debris or have it check the light’s existence before destroying it in case the player leaves/dies.