Why won't the effects of my pepper spray work?

  1. Hello! I’m currently making a pepper spray tool. When the player is sprayed, they get an orange GUI on their screen to block their vision and lose 5 health/second.

  2. When the BindableEvent is fired, the only effect that works is losing 5 health/second. The GUI won’t work. I have no clue how to transfer it over.

  3. I’ve tried asking in two servers and looking it up on the developer.roblox.com, but could not find any answers.

LOCALSCRIPT 1

local hitPart = script.Parent.Parent.SprayPart
hitPart.Touched:Connect(function(hit)
	for _, player in pairs(ps:GetPlayers()) do
		if hit.Parent == player.Character then
			spraying = true
			if spraying == true then
				wait(1)
				script.Parent.Parent.sprayEffects:Fire(hit.Parent)
			end
		end
	end
end)

LOCALSCRIPT 2

local sg = game:GetService("StarterGui")
local sprayed = sg.PepperSprayGUI.PepperSprayed

re.Event:Connect(function(hit, spraying)
	repeat
		hit.Humanoid.Health =-5
	until hit.Humanoid.Health == 0
	repeat
		sprayed.BackgroundTransparency = sprayed.BackgroundTransparency - .1
	until sprayed.BackgroundTransparency == 0
end)

Thank you for reading! Please give me any advice that you have.

You could use a remoteEvent with a Client>Server>Client2 request, however make sure that the server verify if the player (target) is close enought before firing the request to Client2 as it could be exploited by exploiters to hide the view of everyone in the server.

See : RemoteEvent | Roblox Creator Documentation

*Please ignore my first reply where I mentioned Client>Client communications as it isn’t possible.

Do you have any examples? Still a bit confused
(also i think you can do client to client via a bindableevent)

Peer-to-peer would be incredibly unsafe for Roblox (mainly for security). It is not possible to go from Client A to Client B directly.

How could I do it the way that he said then? I have no clue to be honest.

Go read about RemoteEvent on RemoteEvent | Roblox Creator Documentation.

Here is the situation, client1 is the player with the pepper spary. Client2 is the player who is the “target” of the spray.

Client1 will fire the remoteEvent to the server with the argument of “client2”, the server, uppon recieving the request, will verify if client1 is close enought of client2. If the two players are close enought, the server will fire a remoteEvent to client2, who will then have his view hidden by your GUI

BindableEvent only work for the type of script who fired it.

If a localscript fire a BindableEvent, the event will only triggers localscript on the player client who fired it. It is useful to allow communications between two or more local script on the same client.
If a server fire a BindableEvent, only scripts on the server-side will be able to see it, again allowing communications between multiples server-side script.

See : BindableEvent | Roblox Creator Documentation