How to run a local script when a brick is touched?
Place the local script in StarterPlayerScripts.
I rewrote your code in a slightly better way. Place this code in the local script
Lighting = game:GetService('Lighting')
game.Workspace.Five.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') then
print('Runned')
Lighting.inverted1.Enabled = true
Lighting.inverted2.Enabled = true
end
end)
It's recommended to usegame:GetService('Service name')
to use services.
I also changed if hit.Parent == game.Players.LocalPlayer.Character then
for if hit.Parent:FindFirstChild('Humanoid') then
because it's simpler and the code runs faster than the character loads, so it gives an error and stops running.
Link with GetService() API reference: https://developer.roblox.com/en-us/api-reference/function/ServiceProvider/getService