What is the best way of handling this?

So basically i have abilities that players can use, The way it works is that players will click a button and it will fire a remote event to the server. And from there, the server can do whatever it needs to.

But i have a few abilities that do certain things only the player using the ability should see, Like highlighting other players and stuff like that. I’m pretty sure i should send a remote event back to the client to display the effects. But there are multiple abilities that do this kind of thing, But like with different effects or different highlight colors. I would like to know the best and most efficient way to do this. I couldn’t really find any other posts like this because it’s a pretty specific thing

i have probably made like a thousand posts like this asking what the best way of doing something is

2 Likes

Hello there!

What i understood is that you have different buffs for the players that are very similar, just changing colors and small things right?

What I would do is to fire a remote event from the server to the client, and link this remote event to a module script with the abilities code.

On the code, what you can do to easy out your job is to make a table with the different aspects of each buff like

Local Buffs = {
Buff1 = {true, Color.FromRGB(255,0,0), 10},
Buff2 = {true, Color.FromRGB(0,255,0), 5},
Buff3 = {false, nil, 5, true}
}

To access the values

Local ValueOrder = {
Highlight,
Color,
Duration,
OtherStuff
}

If _WantedValue == Table.Find(Buffs, (Table.find(ValueOrder, _WantedValue, 1), 1) then

Do the thing!!!

End

Then the values on the tables woulds say what each buff is for.

Maybe a bit confusing, and probably theres a better way to do it, but i hope it helps :wink:

2 Likes

put a script in serverscriptservice

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AbilityEvent = ReplicatedStorage:WaitForChild("AbilityEvent")

local function onAbilityActivated(player, abilityName, targetPlayer)
    local effectData = {
        color = Color3.new(1, 0, 0),
        effectType = abilityName,
    }

    if abilityName == "HighlightAbility" then
        effectData.color = Color3.new(0, 1, 0) 
    elseif abilityName == "AnotherAbility" then
        effectData.color = Color3.new(0, 0, 1) 
    end

    AbilityEvent:FireClient(player, effectData, targetPlayer)
end

AbilityEvent.OnServerEvent:Connect(onAbilityActivated)

put a local script in starterplayerscripts

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AbilityEvent = ReplicatedStorage:WaitForChild("AbilityEvent")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local function applyEffect(effectData, targetPlayer)
    local targetCharacter = targetPlayer.Character
    if targetCharacter then
        local highlight = Instance.new("Highlight")
        highlight.Adornee = targetCharacter
        highlight.FillColor = effectData.color
        highlight.FillTransparency = 0.5
        highlight.Parent = targetCharacter

        wait(2)
        highlight:Destroy()
    end
end

AbilityEvent.OnClientEvent:Connect(applyEffect)
1 Like

I did some tests and i found one way that seems to work well for me
Basically, i just send the ability name to the client through a remote event, and the client can do everything else from there
I’m not sure if this is the best way to do it, but it makes this much easier for me (its a really simple thing i know, but i think this way is fine)

Thanks to everyone for all the help!

1 Like