Help with Blur on Touch System

local Lighting = game:GetService'Lighting'
local Players = game:GetService'Players'
local LocalPlayer = Players.LocalPlayer

local function OnTouched(Touched)
	local Player = Players:GetPlayerFromCharacter(Touched.Parent)
	if Player and Player == LocalPlayer then
		Lighting.FogEnd = 10
	end
end

script.Parent.Touched:connect(function(hit)
	if not script.Parent.Parent.Fire.Spray.Enabled then return end
	if game.Players:GetPlayerFromCharacter(hit.Parent) then
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		plr.Character.Humanoid.Sit = true
		if plr and plr == LocalPlayer then
			Lighting.HighBlur.Enabled = true
			wait(30)
			Lighting.HighBlur.Enabled = false
			Lighting.MediumBlur.Enabled = true
			wait(30)
			Lighting.MediumBlur.Enabled = false
			Lighting.LightBlur.Enabled = true
			wait(60)
			Lighting.LightBlur.Enabled = false
		end
		game.ReplicatedStorage.PepperEvents.Peppered:Clone().Parent = plr.PlayerGui
	end
end)

So, when the user gets peppersprayed, their client should turn on HighBlur(lighting fx) and mediumBlur, LowBlur, then its over.
Includes wait times.
So I just tested it, theres no errors. Can someone help me fix this?

local Lighting = game:GetService('Lighting')
local Players = game:GetService('Players')
local LocalPlayer = Players.LocalPlayer

local function OnTouched(Touched)
    local Player = Players:GetPlayerFromCharacter(Touched.Parent)
    if Player and Player == LocalPlayer then
        Lighting.FogEnd = 10
    end
end

script.Parent.Touched:Connect(function(hit)
    if not script.Parent.Parent.Fire.Spray.Enabled then
        return
    end
    local player = Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        local character = hit.Parent
        if character then
            local humanoid = character:FindFirstChildOfClass('Humanoid')
            if humanoid then
                if not humanoid.Sit then
                    humanoid.Sit = true
                    if player == LocalPlayer then
                        Lighting.HighBlur.Enabled = true
                        wait(30)
                        Lighting.HighBlur.Enabled = false
                        Lighting.MediumBlur.Enabled = true
                        wait(30)
                        Lighting.MediumBlur.Enabled = false
                        Lighting.LightBlur.Enabled = true
                        wait(60)
                        Lighting.LightBlur.Enabled = false
                    end
                    game.ReplicatedStorage.PepperEvents.Peppered:Clone().Parent = player.PlayerGui
                end
            end
        end
    end
end)

What part exactly does not work?

The player ends up only sitting. I checked into the players local lighting, and no blurs enabled.
This script isn’t in serverscriptservice, and it’s not a localscript. It’s a serverscript.
Could one of those be the issue?

@MrFergxl
Okay, for some reason

local Lighting = game:GetService('Lighting')
local Players = game:GetService('Players')
local LocalPlayer = Players.LocalPlayer

script.Parent.Touched:Connect(function(hit)
	if not script.Parent.Parent.Fire.Spray.Enabled then
		return
	end
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		local character = hit.Parent
		if character then
			local humanoid = character:FindFirstChildOfClass('Humanoid')
			if humanoid then
				if not humanoid.Sit then
					humanoid.Sit = true
					if player == LocalPlayer then

if player == LocalPlayer - returns false, using breakpoints + basic debug.
Why is that happening

But this is a serverscript, so maybe thats the issue with getting local player?

Try and see if that’s the case. If not, let me know

I can’t test it right now but I’d assume.
As you need a localscript to get the localplayer, but I’m not sure if the script would work completely properly as it was meant to be a serverscript, do you think it’ll work?

You can’t get LocalPlayer from a server script.

local function OnTouched(Touched)
	local Player = Players:GetPlayerFromCharacter(Touched.Parent)
	if Player and Player == LocalPlayer then
		Lighting.FogEnd = 10
	end
end

Your issue is with Player == LocalPlayer.

Server scripts cannot get LocalPlayer. Additionally, it can’t change the lighting for one specific person, as if you try to change the lighting from a server script, it changes the lighting for everyone else.

The solution? Turn this into a local script, get rid of parts that don’t make sense in the local script. Hopefully, it should work.

local Lighting = game.Lighting
local Players = game.Players
local LocalPlayer = Players.LocalPlayer
local Sound = game.SoundService.Breath

script.Parent.Touched:Connect(function(hit)
	if not script.Parent.Parent.Fire.Spray.Enabled then
		return
	end
	local player = Players:GetPlayerFromCharacter(hit.Parent)
	if player then
		local character = hit.Parent
		if character then
			local humanoid = character:FindFirstChildOfClass('Humanoid')
			if humanoid then
				if hit then
					Sound:Play()
					Sound.Looped = true
					wait(60)
					Sound.Looped = false
					Lighting.HighBlur.Enabled = true
					wait(30)
					Lighting.HighBlur.Enabled = false
					Lighting.MediumBlur.Enabled = true
					wait(30)
					Lighting.MediumBlur.Enabled = false
					Lighting.LightBlur.Enabled = true
					wait(60)
					Lighting.LightBlur.Enabled = false
				end
					end
				end
	end
end)






I ended up with this,(now a localscript), the audio will play, thankfully, but it’s player on the player whos spraying, as I realize Im getting the player who is spraying, how can I get the player who was sprayed? The players lighting still will not change also, I would need to do this:

SprayedPlayer.Audio:Play(etc all that)

SprayedPlayer.Lighting.HighBlur.Enabled = true
wait(60)

etc, how can I do this?

Unfortunately I am not home rn I will get back to u ASAP on this topic. I’ll be back home in like 1-2 days if someone else cannot answer it.

I can try to answer it rn but I can’t really write any code.

A way to get the person that was peppersprayed is to make the pepper spray a hitbox. Then, create a script that detects the player, similarly like a killbrick for an obby game.

Okay, so I did end up fixing everything which is nice.
But, it seemed to have hit the pepperspray operator, and the victim.
Is there a way to make sure it cant spray the operator?

Definitely! Just add an if statement where if the characters name is the same as the local player, it just doesn’t do anything. Or u can just make the hitbox farther away

Thanks, I’ll try soon. I’ll probably end this post, as it’s no longer needed(may may have given up…) but, if it works ill continue