Why does the ball disappear

so I’m using kinematic formula for simulating a ball kick and it was working for a while and i didnt touch the script at all and it just broke just completely it disappears and deletes from the workspace and I’ve tried everything i can think of I’ve made sure no script was deleting the ball i set the network ownership I’ve made sure the physics aren’t breaking and I’ve even had ai analyze the code and nothing works so im kind of lost on what to do

heres a vid
https://gyazo.com/1029415102c022cdde459e6505afd7ad

Well there’s a lack of information you’re not showing us (not to be rude). So I don’t believe anyone can help you with this issue unless you show more of the code on how the ball functions.

oh srry here is the script im using to simulate the ball

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local clientEffects = ReplicatedStorage.Remotes

local Shoot = {}

function Shoot.new(Gravity, WhiteList, Radius, Wind, Despawntime, MaxBounces, Decay, Threshold, Visulize)
	local newKick = {}

	newKick.Gravity = Gravity 
	newKick.Wind = Wind 
	newKick.Threshold = Threshold 
	newKick.MaxBounces = MaxBounces
	newKick.Decay = Decay 
	newKick.Radius = Radius 
	newKick.Despawntime = Despawntime 
	newKick.Visulize = Visulize
	newKick.Params = RaycastParams.new()

	newKick.Params.FilterType = Enum.RaycastFilterType.Include
	newKick.Params.FilterDescendantsInstances = WhiteList

	function newKick:Cast(start, dest, vel)
		local conversion = 196.2 / 9.8
		local velocity = (dest - start).Unit * vel * conversion

		local a = Vector3.new(self.Wind.X , self.Wind.Y - self.Gravity * 9.8, self.Wind.Z) * conversion
		 

		local t = 0
		local totalTime = 0
		local bounces = 0
		local currentPos = start
		local rayResult = nil
		local found = false
		
		local currentVelocity
		
		local index = tick()
		clientEffects.BallShoot:FireAllClients(index)

		while not found do
		local dt = task.wait()
			  if not found then
		  	t += dt
			totalTime += dt

			currentVelocity = velocity + a*t
			
			
			local projPos = Vector3.new(
					start.X + velocity.X*t + 0.5*a.X*t*t,
					start.Y + velocity.Y*t + 0.5*a.Y*t*t,
					start.Z + velocity.Z*t + 0.5*a.Z*t*t
			)

			rayResult = workspace:Spherecast(currentPos, self.Radius, projPos - currentPos, self.Params)

			clientEffects.BallUpdate:FireAllClients(index, currentPos, projPos)
			currentPos = projPos



			if rayResult then
			if bounces >= self.MaxBounces then
				found = true
			else
				local Normal = rayResult.Normal
				
						velocity = self.Decay * (currentVelocity - 2 * (currentVelocity:Dot(Normal)) * Normal)
						
						if velocity.Magnitude < self.Threshold then
							found = true
						end
						start = rayResult.Position + Normal * self.Radius
						currentPos = start
						t = 0
						
						bounces += 1
			   end
			end
				if totalTime > self.Despawntime then
					found = true
			end	
		end
	end
		if rayResult then
		    end	
		 end
		 
	return newKick
end

return Shoot

When this event fires and makes a replica to the client, there could be something on that local script that deletes it when it reaches the end (my guess).

i see what you mean but there is nothing there that should be deleting the ball all the client is doing is updating the balls position

May I see the client script? If its not that then maybe a force that builds up and flings it out of bounds, from what I see in the clip.

Edit: maybe its not a force build up but in the clip it legit looks like it gets deleted ¯_(ツ)_/¯

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local Workspace = game:GetService("Workspace")

local player = Players.LocalPlayer
local mouse = player:GetMouse()

 local modules = ServerScriptService

local ball = workspace:FindFirstChild("Ball")
local ballshoot = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("BallShoot")
local ballupdate = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("BallUpdate")
local ShootEvent = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("ShootEvent")


 local remotes = ReplicatedStorage.Remotes
 
local holding = false
local holdStartTime = 0
local maxHoldTime = 2 -- Max time (seconds) to charge power
local minForce = 1.5  -- Minimum force when tapping
local maxForce = 7

local idleAnimationID = "rbxassetid://87720210665475"
local ShootAnimationID = "rbxassetid://100084889618013"

local idleAnimationTrack
local shootAnimationTrack

 
local function stopAnimation(animationTrack)
	if animationTrack then
		animationTrack:Stop()
	end
end

local function PlayAnimation(animationId)
	stopAnimation(idleAnimationTrack)
	stopAnimation(shootAnimationTrack)

	local animation = Instance.new("Animation")
	animation.AnimationId = animationId
	local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		local animationTrack = humanoid:LoadAnimation(animation)
		animationTrack:Play()
		return animationTrack
	end
end


local function onKeyFrameReached(keyframeName)
	if keyframeName == "Shoot" and shootAnimationTrack then
      
			 
 
		
	end
end

mouse.Button1Down:Connect(function()
	holding = true
	holdStartTime = tick()

	idleAnimationTrack = PlayAnimation(idleAnimationID)
end)

mouse.Button1Up:Connect(function()
	if holding then
		holding = false
		stopAnimation(idleAnimationTrack)
		shootAnimationTrack = PlayAnimation(ShootAnimationID)
 
		if shootAnimationTrack then
			shootAnimationTrack.KeyframeReached:Connect(onKeyFrameReached)
 
			local holdDuration = math.min(tick() - holdStartTime, maxHoldTime) -- Limit hold time
			local force = minForce + (holdDuration / maxHoldTime) * (maxForce - minForce)

			print("Hold Duration:", holdDuration) -- Debugging
			print("Calculated Force:", force)
			ShootEvent:FireServer(mouse.Hit)
 
		end
	end
end)
local ballshoot = game.ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("BallShoot")

local balls = {}

local function ballShoots(index)
	local newBall = workspace:FindFirstChild("Ball")
	if newBall then
		balls[index] = newBall
		 
	else
		warn("Ball not found in workspace!")
	end
end
local function ballUpdate(index, currentPos, projPos)
	local currentball = balls[index] or workspace:FindFirstChild("Ball")
		if currentball then
		 
			currentball.Position = currentPos  -- Move the ball
		 


		end
	end

 
ballshoot.OnClientEvent:Connect(ballShoots)
ballupdate.OnClientEvent:Connect(ballUpdate)

Well you’re right on the it doesn’t get deleted on the script part. Wow then I wouldn’t really know what could be causing it to get deleted other than the force or some property on the ball.

Sorry Can’t help you here.

thanks for at least trying idk what to do

Kick ball and then Switch to Server’s view to see if it deletes server-sidely ? (just try)

Newkick.DespawnTime does delete or not ?

honestly this is confusing situation to see Ball delete althought there is not :Destory (guessing)

hmm this is weird on the server its saying the ball is going through the void but on the client it just deletes

1 Like

could you please provide video ?

it might be something client thing (maybe i am dumb)

Are you streaming that game. It looks like it.

Or it's this
if totalTime > self.Despawntime then
    found = true
end

https://gyazo.com/e9d44b3a69a5dd2022965fc7ff5c2f7e heres a video

thats for just when the raycasting is finished it should have nothing to do with deleteing the ball is that what you were asking?

1 Like

This is a module script containing what looks like a shoot class, are you running this on the server? If yes, can I see that code?

sure right here is the server script that requires the module

local Ball = script.Parent
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")

local hitbox = module.CreateHitbox()
hitbox.Size = Vector3.new(4, 1.578, 3.324)
hitbox.CFrame = Ball.handle
hitbox.VelocityPrediction = true
hitbox.VelocityPredictionTime = 0.1
hitbox.DetectionMode = "ConstantDetection"
hitbox.VisualizerTransparency = 0.5

local shootevent = ReplicatedStorage.Remotes.ShootEvent


local camera = game.Workspace.CurrentCamera
   
   local projectile = require(game.ServerScriptService.Modules.Shoot).new(0.75,workspace.Map:GetChildren(),0.72,Vector3.new(0,0,0),7,1000,0.8,5,false)


hitbox.Touched:Connect(function(hit)
   local character = hit.Parent
   local player = Players:GetPlayerFromCharacter(character)
   local humanoid = character and character:FindFirstChild("Humanoid")
   local root = character and character:FindFirstChild("HumanoidRootPart")

   local InPossesion = Ball:GetAttribute("InPoss")
   if Ball:GetAttribute("InPoss") == true then return
   	
   end
       
   	local Torso = character:FindFirstChild("Torso")
   	
   local handle = Ball:FindFirstChild("handle")
   local cframevalue = Ball:FindFirstChild("Value")
   	
   	local ballAnim
   ballAnim = Ball.AnimationController.Animator:LoadAnimation(Ball.BallRoll)
   	ballAnim:Play()
   	local moter6d = Instance.new("Motor6D")
   	moter6d.Part0 = Torso
   	moter6d.Part1 = handle
   	moter6d.C1 = cframevalue.Value
   	moter6d.Parent = handle
   	moter6d.Name = "motor6D"
   Ball.CanCollide = false
   Ball:SetAttribute("InPoss", true)
   character:SetAttribute("InPossesion", true)
end)
hitbox:Start()


shootevent.OnServerEvent:Connect(function(player, Hit, force)
   Ball:SetNetworkOwner(player) -- Force the server to handle physics
   Ball.CanCollide = true
   Ball.Anchored = false
   Ball.Massless = false
   Ball.CustomPhysicalProperties = PhysicalProperties.new(1, 0.3, 0.5, 1, 0.8)```

and this is the module script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

local clientEffects = ReplicatedStorage.Remotes

local Shoot = {}

function Shoot.new(Gravity, WhiteList, Radius, Wind, Despawntime, MaxBounces, Decay, Threshold, Visulize)
	local newKick = {}

	newKick.Gravity = Gravity 
	newKick.Wind = Wind 
	newKick.Threshold = Threshold 
	newKick.MaxBounces = MaxBounces
	newKick.Decay = Decay 
	newKick.Radius = Radius 
	newKick.Despawntime = Despawntime 
	newKick.Visulize = Visulize
	newKick.Params = RaycastParams.new()

	newKick.Params.FilterType = Enum.RaycastFilterType.Include
	newKick.Params.FilterDescendantsInstances = WhiteList

	function newKick:Cast(start, dest, vel)
		local conversion = 196.2 / 9.8
		local velocity = (dest - start).Unit * vel * conversion

		local a = Vector3.new(self.Wind.X , self.Wind.Y - self.Gravity * 9.8, self.Wind.Z) * conversion
		 

		local t = 0
		local totalTime = 0
		local bounces = 0
		local currentPos = start
		local rayResult = nil
		local found = false
		
		local currentVelocity
		
		local index = tick()
		clientEffects.BallShoot:FireAllClients(index)

		while not found do
		local dt = task.wait()
			  if not found then
		  	t += dt
			totalTime += dt

			currentVelocity = velocity + a*t
			
			
			local projPos = Vector3.new(
					start.X + velocity.X*t + 0.5*a.X*t*t,
					start.Y + velocity.Y*t + 0.5*a.Y*t*t,
					start.Z + velocity.Z*t + 0.5*a.Z*t*t
			)

			rayResult = workspace:Spherecast(currentPos, self.Radius, projPos - currentPos, self.Params)

			clientEffects.BallUpdate:FireAllClients(index, currentPos, projPos)
			currentPos = projPos



			if rayResult then
			if bounces >= self.MaxBounces then
				found = true
			else
				local Normal = rayResult.Normal
				
						velocity = self.Decay * (currentVelocity - 2 * (currentVelocity:Dot(Normal)) * Normal)
						
						if velocity.Magnitude < self.Threshold then
							found = true
						end
						start = rayResult.Position + Normal * self.Radius
						currentPos = start
						t = 0
						
						bounces += 1
			   end
			end
				if totalTime > self.Despawntime then
					found = true
			end	
		end
	end
		if rayResult then
		    end	
		 end
		 
	return newKick
end

return Shoot```

Are you sure you provided the entire script? It looks like the server script is cut off.

What do you mean by this? From the video you sent it looks like the ball just went ahead, its y coordinate is barely changed.

You are doing the opposite of what the comment says, this would make the player’s client handle the physics instead…