How to run a local script when a brick is touched?

Viewed 1044

So, I'm looking to run a script on a players client that basically activates 2 -1 saturation color correction effects to invert the colors on their screen and their screen only, but I've only been scripting for a few months, and I'm not really ready to write complex code.

here is the code:

   game.Workspace.Five.Touched:Connect(function(hit)
        if hit.Parent == game.Players.LocalPlayer.Character then
            game.Lighting.inverted1.Enabled = true
            game.Lighting.inverted2.Enabled = true
        end
    end)
2 Answers

Place the local script in StarterPlayerScripts.

enter image description here

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

ok i have solved it, using remote events i got the player that touched the brick and used the server to handle the color correction enabling

Related