The fireball gets delayed in the client, So, In the server, It is not in the same position as the client.
When the player clicks the tool fire server to a server script in the tool after that, The fireball gets cloned and edited and Then applies a linear velocity to it and Gets fire.
Server script:
--Server
local Tool = script.Parent
local Remotes = Tool["Remotes."]
Remotes["Equipped."].OnServerEvent:Connect(function(Player)
local Character = Player.Character or Player.CharacterAdded:Wait()
Character["Right Arm"]:FindFirstChild("RightGrip"):Destroy()
local Joint = Instance.new("Motor6D")
Joint.Name = "RightGrip"
Joint.Parent = Character["Right Arm"]
Joint.Part0 = Character["Right Arm"]
Joint.Part1 = Tool.Handle
end)
Remotes["Unequipped."].OnServerEvent:Connect(function(Player)
local Character = Player.Character or Player.CharacterAdded:Wait()
Character["Right Arm"]:FindFirstChild("RightGrip"):Destroy()
end)
Remotes["Activated."].OnServerEvent:Connect(function(Player, Direction: Vector3)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://17299679453"
Sound.Parent = Character.PrimaryPart
Sound:Play()
local FireBall = nil
if Player.Team ~= game.Teams["Wizard Outlaws"] and Player.Team ~= game.Teams["Wizard Prisoners"] then
FireBall = Tool["Gaurds fire particle"]:Clone()
elseif Player.Team == game.Teams["Wizard Outlaws"] or Player.Team == game.Teams["Wizard Prisoners"] then
FireBall = Tool["Outlaws fire particle"]:Clone()
end
FireBall.Parent = Character
FireBall:SetAttribute("Enabled", true)
FireBall:SetAttribute("PlayerName", Player.Name)
for Index, Descendant in FireBall:GetDescendants() do
if Descendant:IsA("ParticleEmitter") and Descendant.Parent.Name ~= "Fire." then
Descendant.Enabled = true
end
end
FireBall.CFrame = Character["Right Arm"].CFrame * CFrame.new(0,0,-4)
local BodyForce = Instance.new("BodyForce")
BodyForce.Parent = FireBall
BodyForce.Force = Vector3.new(0,workspace.Gravity * FireBall:GetMass(),0)
local LinearVelocity = Instance.new("LinearVelocity")
LinearVelocity.Parent = FireBall
LinearVelocity.Attachment0 = FireBall.Attachment
LinearVelocity.VectorVelocity = CFrame.new(Character.HumanoidRootPart.Position, Direction).LookVector * 150
end)
Client script:
local Tool = script.Parent
local Remotes = Tool["Remotes."]
local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
local Animator: Animator = Humanoid:WaitForChild("Animator")
local WandIdleAnimation = Animator:LoadAnimation(Tool["Wand idle animation."])
local AttackAnimation = Animator:LoadAnimation(Tool["Wand Animation."])
local Cooldown = 0
Tool.Equipped:Connect(function()
Remotes["Equipped."]:FireServer()
WandIdleAnimation:Play()
end)
Tool.Unequipped:Connect(function()
Remotes["Unequipped."]:FireServer()
WandIdleAnimation:Stop()
end)
Tool.Activated:Connect(function()
if Cooldown > 0 then return end
local Mouse = Player:GetMouse()
local MousePosition = Mouse.Hit.Position
Tool["Remotes."]["Activated."]:FireServer(MousePosition)
AttackAnimation:Play()
Cooldown = 1
end)
coroutine.wrap(function()
while wait(1) do
Cooldown = Cooldown - 1
end
end)()
okay so what im guessing is you anchor the fireball after it hits something?
This might cause problems since the fireball is in a different position on the client than on the server when it gets anchored. ive had a similar problem before and an easy way to fix it is to move the fireball up by 0.001 then down by 0.001. That used to work for me but you can try for yourself and see. (Move the fireball after its anchored)
Thatâs moslty because youâre doing it in a wrong way, the fireball projectile and effects should be made on the client side.
The correct way to do it is:
Client: Tool activated > Do some check (cooldowns ectâŠ) > do the fireball projectile + effects > FireServer(Mouse.Position)
Server: Do some check (cooldowns ectâŠ) > FireAllClient(OriginalPlayer, TargetPosition) > cast damage
All Clients: do the fireball projectile + effects only if the OriginalPlayer is not you (not OriginalPlayer == Local Player)
This way, the fireball will be instantly thrown from your point of view, the server will do some sanity checks to see if thereâs no exploits and then cast the damages and replicate the fireball to all other players point of view on their client side.
This way the server does not have to replicate the information you change after it gets parented to every single client (This can be bad on performance and maybe cause slight delays)
Like I said it may not have a large effect on performance, but itâs good if youâre trying to optimize this code to work faster.
And you donât have to put the parents last last, just make sure itâs the last thing you do AFTER changing variables specifically for the thing youâre thing to parent
This way if you change say, volume and name of a sound object after itâs been parented, those properties donât have to be replicated to EVERY client at the same time, instead parent before changing variables, so when the object does get parented all the client has to do is receive one object instead of an object and 2 more property changes afterwards.