Hey guys, it’s agKing here and today I have a problem in which I struggle to blur player vision so basically I have 2 effects in the lightning in which one is for the ligh and the other is for bluring so here are the 2 effects
Here’s the code from getNearestPlayer() and the code for sending the remote event to the player what we want to blind
local function getNearestPlayer(originPlayer, maxDistance)
local originCharacter = originPlayer.Character
if not originCharacter then return nil end
local originRootPart = originCharacter:FindFirstChild("HumanoidRootPart")
if not originRootPart then return nil end
local originPos = originRootPart.Position
local closestPlayer, closestDist = nil, math.huge
for _, player in pairs(game.Players:GetPlayers()) do
if player ~= originPlayer and player.Character then
local targetRootPart = player.Character:FindFirstChild("HumanoidRootPart")
if targetRootPart then
local targetPos = targetRootPart.Position
local dist = (targetPos - originPos).Magnitude
if dist < closestDist and (not maxDistance or dist <= maxDistance) then
closestPlayer, closestDist = player, dist
print("Type of closestPlayer:", typeof(closestPlayer))
print("ClassName of closestPlayer:", closestPlayer.ClassName)
end
end
end
end
return closestPlayer
end
ObjectItems.Events.BlindSomeone.OnServerEvent:Connect(function(player)
local closestPlayer = getNearestPlayer(player, math.huge)
if closestPlayer and closestPlayer:WaitForChild("IsParticipating").Value == true then
print("Nearest player is :", closestPlayer.Name)
print("CLOSEST PLAYER IS : ", closestPlayer)
print("PLAYER IS : ", player)
ObjectItems.Events.BlindSomeone:FireClient(closestPlayer)
else
print("No Player has been found")
end
end)
you need to create a RemoteEvent in ReplicatedStorage to send the blur effect to the client. The code you provided fine, just add a client side script to handle the blur effect when the RemoteEvent is triggered.
take this is an example:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local blurRemote = ReplicatedStorage:WaitForChild("BlurRemoteEvent")
local blurEffect = Instance.new("BlurEffect")
blurEffect.Parent = game.Lighting
blurEffect.Size = 0 -- Start with no blur
blurRemote.OnClientEvent:Connect(function()
blurEffect.Size = 25 --your preferred value
wait(5) --
blurEffect.Size = 0 -- Remove the blur
end)
If yes; try enabling the effects in studio while playing, do they work? is something turning them off?
If no; double check if the events are the same, is the correct player printing?
It means that closestPlayer that I want to blind is a valid player instance but somehow the code doesn’t want to send the request to the client of the closestPlayer but when I do it on my own player it works perfectly fine but I don’t want to target my own player because I’m the attacker