Hey so i have this fireball script and the thing is the blast stops before comppletly touching the player its hard to explain but ill just show a video and also when its fired it stops for a second then it blasts idk what cause it too
local rem = script.Parent:WaitForChild("RemoteEvent")
rem.OnServerEvent:Connect(function(player, MousePosition)
local fb = game.ReplicatedStorage.Blast:Clone()
fb.Parent = workspace
fb.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -2)
local Newfb = Instance.new("BodyForce")
Newfb.Force = Vector3.new(0, workspace.Gravity * fb:GetMass(), 0)
Newfb.Parent = fb
-- Calculate the direction to the mouse position
local direction = (MousePosition - fb.Position).unit
fb.Velocity = direction * 50
local debounce = false -- Add debounce to prevent multiple touches
fb.Touched:Connect(function(hit)
if debounce == false and hit.Parent:FindFirstChild("Humanoid") and not hit:IsDescendantOf(player.Character) then
debounce = true -- Activate debounce to prevent further touch processing
fb.Anchored = true -- Stop the projectile by anchoring
fb.Velocity = Vector3.new(0, 0, 0) -- Ensure velocity is set to zero
if fb:FindFirstChild("BodyForce") then
fb.BodyForce:Destroy() -- Remove the force
end
wait(1) -- Wait for 1 second before dealing damage and destroying the part
hit.Parent.Humanoid:TakeDamage(50)
fb:Destroy() -- Destroy the projectile after dealing damage
end
end)
end)
It’s happening because the wait(1) is causing the script to yield for 1 second, so your part is just sitting there during that time. Few ways you can go about it, the simplest way be replacing
wait(1) -- Wait for 1 second before dealing damage and destroying the part
hit.Parent.Humanoid:TakeDamage(50)
fb:Destroy()
^ These offer full in depth explanations but basically it allows you to schedule a :Destroy() call on an object without yielding, similiar to using a couroutine.
Edit: Ok ignore me- the AddItem(fb,1) is still gonna cause it to be there fore 1 second, so instead itd be
no i meant when the first time the fireball spawn it stays next to the player for a seocnd and then fires and also it still has the same glitch thats in the vid
Oh- thats called network latency. Its the result of the part being spawned in and initially under network ownership of the server, but because its right next to you and unachored, you become the Network Owner almost instantly after its spawned. That handoff between the server to your computer causes jitters when trying to sync physics. You can fix it in multiple ways, wiki talks about it,
I have an error in the script for some reason it goes through the target and only like a seocnd after it touches the player it destroys is there any way to make it destroy instantly when touched a character
Based on the original code you posted, the problem is most likely the wait(1), you also change a bunch of properties and then proceed to destroy the part right afterwards, making all those changes a bit pointless.
Here’s a simplified version of the code that should fix your problem:
fb.Touched:Connect(function(hit)
if not debounce and hit.Parent:FindFirstChild("Humanoid") and not hit:IsDescendantOf(player.Character) then
debounce = true -- Activate debounce to prevent further touch processing
fb:Destroy() -- Destroy the part
hit.Parent.Humanoid:TakeDamage(50) -- Damage the character
end
end)
Should also be noted that using .Touched is notoriously unreliable for situations that require high fidelity collision detection as there will always be some replication latency due to the time it takes for the server to update your client etc.
It’s also not entirely secure from exploiters as .Touched requires at least one of the two colliding objects to be unanchored to fire the event, thus you should perform sanity checks on the server following this if its an important event (i.e. are the two parts close enough that they could have reasonably touched. If the parts are 2 studs away then sure, if theyre 200 studs away, its probably not legit,)