You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? I want to reduce the server load by making the VFX client-sided.1) Orig player will create the VFX locally and fire a remote → 2) Server script will detect that and fire to all clients the location of the VFX → 3) Other clients will receive that event and replicate the VFX on the location of the orig player.
-
What is the issue? I’ve achieved creating the VFX locally for the client but I have no idea on how to replicate the VFX of the local script to the other players. I want 2 scripts only: the local script under the tool (which will handle both the creation of the VFX for the orig player and will also replicate for the other clients) and the server script (which will receive the event fired and fire back to other clients and other clients on their local script will replicate the VFX).
- What solutions have you tried so far? I’ve tried creating it server-sided which works but has a high server load. I came across this post but I’m having trouble understanding the logic of how he was able to create this using only the client side script and a server script: Full Beginner's Guide on scripting Anime/Fighting VFX(Visual Effects) [Part 1]
Also, do I need to create an entirely different local script that will handle the VFX replication of different attacks (limited to 1 script only and just sending properly formatted arguments)? I thought of the problem which was the if the player doesn’t have the tool then the local script wouldn’t be with him and won’t replicate the VFX.
Here’s my code:
Client
-- IcePathLocalScript
local UIS = game:GetService("UserInputService")
local CollectionService = game:GetService("CollectionService")
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
local remote = game.ReplicatedStorage["Attack Related"].RemoteEvents.Ice:WaitForChild("IceMagic")
local isEquipped = false
local origToolName = tool.Name
local COOLDOWN = 2
local debounce = false
-- Function to handle tool being equipped
local function onEquipped()
isEquipped = true
end
-- Function to handle tool being unequipped
local function onUnequipped()
isEquipped = false
end
tool.Equipped:Connect(onEquipped)
tool.Unequipped:Connect(onUnequipped)
local function createIcePath(mousePosition, magicType, inputState)
-- Create the ice path locally for the player who triggered it
-- You can use your previous code for creating the ice path here
if magicType == "IcePath" and inputState == "Holding" then
local icePartTemplate = game.ReplicatedStorage.Items.IceAttacks["Ice Path"]:WaitForChild("IcePathModel")
local icePartTag = "IcePath"
local footOffset
-- Check the player's WalkSpeed and set the footOffset accordingly
if player.Character.Humanoid.WalkSpeed >= 100 then
footOffset = Vector3.new(-0.5, 0, 25) -- Offset the ice part 50 studs in front of the foot
else
footOffset = Vector3.new(-0.5, 0, 10) -- Offset the ice part 20 studs in front of the foot
end
for i = 0, 100 do
wait()
local icePart = icePartTemplate:Clone()
icePart.Parent = game.Workspace.DebrisFolder
icePart.CanCollide = true
icePart.Anchored = true
icePart.CanTouch = true
local character = player.Character
local footPosition = character:WaitForChild("RightFoot").Position
local direction = (mousePosition - footPosition).unit
local rightVector = character.HumanoidRootPart.CFrame.RightVector
local lookVector = character.HumanoidRootPart.CFrame.LookVector
local positionInFrontOfFoot = footPosition + rightVector * footOffset.X + lookVector * footOffset.Z
icePart.CFrame = CFrame.new(positionInFrontOfFoot, positionInFrontOfFoot + direction)
icePart.Orientation = Vector3.new(0, 0, 0)
icePart.Size = Vector3.new(0.001, 0.001, 0.001)
local newSize = Vector3.new(42.84, 0.2, 40.176)
local TweenService = game:GetService("TweenService")
local tweenInfoGrow = TweenInfo.new(
0.2,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0,
false
)
local tweenGrow = TweenService:Create(icePart, tweenInfoGrow, {Size = newSize})
tweenGrow:Play()
tweenGrow.Completed:Connect(function()
CollectionService:AddTag(icePart, icePartTag)
-- New tween for the ice part's duration before shrinking
local tweenInfoShrink = TweenInfo.new(
2,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
false
)
local tweenShrink = TweenService:Create(icePart, tweenInfoShrink, {Size = Vector3.new(0.001, 0.001, 0.001)})
tweenShrink:Play()
-- Add the ice part to debris after it lasts for 1 second
task.delay(2, function()
game.Debris:AddItem(icePart, 0.0001)
end)
-- Send the ice path's position to the server for replication to other clients
remote:FireServer(mousePosition, icePart.Position, magicType, inputState)
end)
end
end
end
-- When the client triggers the ice path
local function onIcePathTriggered()
-- Fire the local function to create the ice path
createIcePath(mouse.Hit.Position, "IcePath", "Holding")
end
UIS.InputBegan:Connect(function(input, processed)
if processed then return end
-- Check if the tool is equipped before taking any input
if isEquipped then
-- Check if the left mouse button is pressed
if input.UserInputType == Enum.UserInputType.MouseButton1 and debounce == false then
debounce = true
-- Call the local function to create the ice path
onIcePathTriggered()
-- Change tool name to the cooldown amount
task.spawn(function()
for i = COOLDOWN, 1, -1 do
tool.Name = "[".. tostring(i).. "]"
wait(1)
end
tool.Name = origToolName
end)
wait(COOLDOWN)
debounce = false
end
end
end)
-- Listen for the server response and create the ice path locally
remote.OnClientEvent:Connect(createIcePath)
Server
-- IcePathServerScript
local remote = game.ReplicatedStorage["Attack Related"].RemoteEvents.Ice:WaitForChild("IceMagic")
remote.OnServerEvent:Connect(function(player, mousePosition, icePartPosition, magicType, inputState)
if magicType == "IcePath" and inputState == "Holding" then
-- Replicate the ice path to all other clients
remote:FireAllClients(player, mousePosition, icePartPosition)
end
end)
P.S. The icePartPosition arguments aren’t really working because I don’t know how to receive it on the other clients that will replicate it on the same exact position as the player. This is my first time posting so bear with me HAHAAH