Hello! I’m nipping the server-sided VFX habit in the bud right now before I get too far along in my scripting journey and have to relearn it all over again. The move I am currently working on has two separate effects, the initial snap and an animation that plays for the victim if someone is hit by the attack.
It is hard for me to really demonstrate but in the video below, imagine that the victim character plays an animation where they get lifted upwards and flung away (Or towards your direction because that’s how the ability works)
My concern is that I know there is an easy way to solve this by making another event that fires all clients if the hitbox on the server connects, but that sounds like it’s too easy to be the most optimal option.
Right now I am currently using 2 remote events, one that fires to the server after pressing Q which generates the hitbox and checks for cooldown and another event that fires every client to show the effects to them. Would adding a 3rd remote event hamper any performance or am I overthinking it and just need to shuffle some code around?
Alongside this! If there if there is a better solution AND there’s a better way to write this in a way that doesn’t use so many remote functions let me know! I’ve just been reading a lot of about them and heard that using too many isn’t the greatest thing.
Below is my VFX Handler (Local Script) and the script that generates the hitbox (Server Script)
Local Script:
local function onGravity(player, hitboxOffset, hitboxCFrame)
local character = player.Character
local hand = character:FindFirstChild("LeftHand")
--local floating = victimCharacter.Humanoid:LoadAnimation(caughtAnim)
local gravity = player.Character.Humanoid:LoadAnimation(fireAnim)
local snapPart = Instance.new("Part")
local snap = effectsFolder.GravityEffects:WaitForChild("Snap")
local snapClone = snap:Clone()
snapPart.Anchored = true
snapPart.CanCollide = false
snapPart.CanQuery = false
snapPart.CanTouch = false
snapPart.Transparency = 1
snapPart.Size = Vector3.new(1,1,1)
snapClone.Parent = snapPart
local sparkle = effectsFolder.GravityEffects:WaitForChild("Sparks")
local zap = effectsFolder.GravityEffects:WaitForChild("Main Core")
local sparkleClone = sparkle:Clone()
local zapClone = zap:Clone()
zapClone.Parent = hand
sparkleClone.Parent = hand
gravity:Play()
gravity:GetMarkerReachedSignal("GravEffect"):Connect(function()
snapSound:Play()
local visualizer = TER:WaitForChild("Visualizer")
snapPart.CFrame = visualizer.CFrame
snapPart.Parent = workspace
task.wait(0.4)
sparkleClone:Destroy()
zapClone:Destroy()
task.wait(0.5)
snapPart:Destroy()
end)
end
gravityVFXEvent.OnClientEvent:Connect(onGravity)
Server Script:
local function serverRecieved(player)
print(player.Name)
if table.find(debounce, player.Name) ~= nil then
print("Under debounce")
else
print("Server Recieved")
table.insert(debounce, player.Name)
local character = player.Character
local humanoid = character:FindFirstChild("Humanoid")
local hrp = character:FindFirstChild("HumanoidRootPart")
local characterDirection = hrp.CFrame.LookVector
local parameters = OverlapParams.new()
parameters.FilterType = Enum.RaycastFilterType.Exclude
parameters.FilterDescendantsInstances = {character}
local hitbox = hitboxModule.CreateHitbox()
hitbox.Shape = Enum.PartType.Block
hitbox.Size = Vector3.new(8, 8, 8)
hitbox.CFrame = character.HumanoidRootPart
hitbox.DetectionMode = "Default"
hitbox.Offset = CFrame.new(0, 0, -20)
hitbox.OverlapParams = parameters
hitbox.Visualizer = true
hitbox.VisualizerTransparency = 0.5
hitbox.VelocityPrediction = true
hitbox.VelocityPredictionTime = 0.2
gravityVFXEvent:FireAllClients(player, hitbox.Offset, hitbox.CFrame)
task.wait(0.4)
hitbox:Start()
hitbox.Touched:Connect(function(hit, humanoid)
local victimCharacter = humanoid.Parent
local victimPlayer = PLRS:GetPlayerFromCharacter(victimCharacter)
local vrp = victimCharacter:FindFirstChild("HumanoidRootPart")
local victimTorso = victimCharacter:FindFirstChild("LowerTorso")
if victimCharacter then
knockbackModule.knockbackAttributes(player, hrp, victimCharacter, vrp, -50, 0, 45, 0)
end
end)
task.wait(0.1)
hitbox:Stop()
task.wait(cooldown)
debounce[table.find(debounce, player.Name)] = nil
end
end
gravityEvent.OnServerEvent:Connect(serverRecieved)