So I’m making a snowball projectile and as you can see in the video there seem’s to be lag with the touched event. It hits the target and does the explosion but as you can see the ball disapears a bit early then expected as on contact the script is told to delete the part and do the explosion effect with client effects. I set networkownership to nil on server before doing velocity. Setting it to player before only made it look natural for me but for other players still delayed. So what do I need to do for the touched event to go off at the right time for everyone???
-- Server Throw script--
elseif Type == "Throw" then
if Rolling.Value == false then
local Animation = Instance.new("Animation")
Animation.AnimationId = BlessingModule["ThrowAnimationID"]
local Throw = Hum:LoadAnimation(Animation)
Throw:Play()
Throw:AdjustSpeed(1.6)
local Snowball = Debris.SearchPlrFolderFor("Snowball",Character.Name)
Snowball.Name = "ThrownSnowball"
spawn(function()
wait(.05)
for i,v in pairs(Snowball:GetChildren()) do
if v:IsA("ParticleEmitter") then
v.Enabled = true
end
end
end)
Debris.rsWait(.28)
Snowball:FindFirstChild("SnowballWeld"):Destroy()
Snowball.CFrame = RightHand.CFrame
Snowball:SetNetworkOwner(nil)
Velocity.AngleAndMouseVelocity(Mouse,Snowball,Snowball,BlessingModule["Speed"],1e8,1e8,1e8,0,0,0,5) -- Velocity Module
Destruction.Touched(Snowball.hitbox,Character,BlessingModule["Damage"],BlessingModule["NoDmgTime"],BlessingModule["ExplosionType"]) -- TOuched event module
Debris.rsWait(1)
if Blessing.Value == "Default" then
Default_Reload(BlessingFolder,Debris,Instances,Character,RightHand)
end
end
end
--Velocity Module Part--
function Velocity.AngleAndMouseVelocity(Mouse,StartPos,Part,Speed,ForceX,ForceY,ForceZ,DirectionX,DirectionY,DirectionZ,Time)
spawn(function()
local Vel = Instance.new("BodyVelocity",Part)
Vel.MaxForce = Vector3.new(ForceX,ForceY,ForceZ)
Vel.Velocity = CFrame.new(StartPos.Position,Mouse.p).LookVector * Speed --+ Vector3.new(DirectionX,DirectionY,DirectionZ)
Debris.rsWait(Time)
Vel:Destroy()
end)
end
--The touched event if ya need to see--
local beenhit = {}
function destruction.Touched(Part,Char,Damage,NoDmgTime,Type)
Part.Touched:Connect(function(hit)
if hit:IsA("BasePart") or hit:IsA("MeshPart") then
if not beenhit[hit.Parent] and hit.Parent.Name ~= Char.Name and not hit:IsDescendantOf(Char) and hit.Name ~= "Shock" and hit.Name ~= "dashpart" and hit.Name ~= "snowdust" and hit.Name ~= "Baseplate1" then
beenhit[hit.Parent] = true
Debris.addItem(Part.Parent,0)
spawn(function()
Debris.rsWait(NoDmgTime)
beenhit[hit.Parent] = false
end)
print(hit.Name)
if hit.Parent:FindFirstChild("Humanoid") then
--DamageRemote:FireServer(hit.parent,Damage,Type,hit)
DamageModule.Person(hit.parent,Damage,Type,hit)
print("HIT HUMANOID")
end
end
end
end)
end