Remote events help

my issue is firing a remote event to only one client. for me it the person with the weapon.

local remote = game.ReplicatedStorage:WaitForChild(“Indicator_Request”)
local player = game.Players.LocalPlayer

local function hitguy()
game.Lighting.Hit_effect.Brightness = 0
task.wait(0.01666666666)
game.Lighting.Hit_effect.Brightness = .1
task.wait(0.01666666666)
game.Lighting.Hit_effect.Brightness = .2
task.wait(0.01666666666)
game.Lighting.Hit_effect.Brightness = .3
task.wait(0.01666666666)
game.Lighting.Hit_effect.Brightness = .2
task.wait(0.01666666666)
game.Lighting.Hit_effect.Brightness = .1
task.wait(0.01666666666)
game.Lighting.Hit_effect.Brightness = 0
end

remote.OnServerEvent:Connect(hitguy)

im trying to achieve a screen effect when a player punches another player but it makes the screen effect visible to the whole server.

You need to separate the scripts.

For example, you would have a script in ServerScriptService that will handles when the player is holding the weapon etc…

Then you would have a local script in StarterPlayerScripts that only the client side can see by the way, and that script will handle all the effects of getting punched.

You use RemoteEvents in ReplicatedStorage to handle the communication between the server and the client. They can be used to send messages to the client, or in your case, it would handle the punch effect.

That’s just a simple explanation of how you would do it. If you need more help let me know.

my game has 2 months worth of work im not seperating any scripts but thanks anyways

You should handle visual effects on the clients’ end, not the server.

This is replicating to every player since it’s being executed on the server.

As @craftpast said , you need client and server scripts to handle different roles.

Well, that’s just how RemoteEvents work; they are meant to communicate between the server and the client. You want the punch effect to be on the client so the whole sever can’t see it.

For example, the script below should fire the event to the player with the weapon.

Server-side script (ServerScriptService)

local remote = game.ReplicatedStorage:WaitForChild("Indicator_Request")

-- Assuming this function is called when a player punches another player
local function onWeaponUsed(player)
    -- Fire the event only to the player who used the weapon
    remote:FireClient(player)
end

-- Hook this function to whatever event signals the weapon being used
-- Example:
-- tool.Activated:Connect(function() onWeaponUsed(player) end)

Then the script below will listen for the event and perform the screen effect only for the player holding the weapon and not the whole server.

Client-Side Script (LocalScript in StarterPlayerScripts or GUI)

local remote = game.ReplicatedStorage:WaitForChild("Indicator_Request")

local function hitguy()
    game.Lighting.Hit_effect.Brightness = 0
    task.wait(0.01666666666)
    game.Lighting.Hit_effect.Brightness = .1
    task.wait(0.01666666666)
    game.Lighting.Hit_effect.Brightness = .2
    task.wait(0.01666666666)
    game.Lighting.Hit_effect.Brightness = .3
    task.wait(0.01666666666)
    game.Lighting.Hit_effect.Brightness = .2
    task.wait(0.01666666666)
    game.Lighting.Hit_effect.Brightness = .1
    task.wait(0.01666666666)
    game.Lighting.Hit_effect.Brightness = 0
end

-- Listen for the RemoteEvent from the server
remote.OnClientEvent:Connect(hitguy)

So now, for example, when ever the player equips the weapon (or however you choose to script it) it will fire the RemoteEvent and the effects will then only happen for that player.

3 Likes

im trying to figure it out i dont understand what im supposed to do

function HitBoxTouched(hit)
if not Equipped or Activated or CanUse then return end
local otherHumanoid = hit.Parent:FindFirstChild(“Humanoid”)
if otherHumanoid then
if hit.CanTouch == true and Hitted then
Hitted = false
if SpecialDamage == true then
SpecialDamage = false
Damages:FireServer()
indicator:FireServer()
SpecialDamages:FireServer()
end
if NormalDamage == true then
Damages:FireServer()
indicator:FireServer()
end
if not CheckHumanoidIgnoreList(otherHumanoid) then
table.insert(humanoidIgnoreList,otherHumanoid)
damagePlayer:FireServer(Player,hit,otherHumanoid,currentDamage,SelectRandomFromArray(hitSounds))
PushForce(hit)
end
end
end
end

the code above is the function that enables the hitbox to hit the aother player.

i got it nevermind i really apreciate it

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.