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
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
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)
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)