I did a tweening animation and when a value is true inn an if statement it is supposed to stop the animation and let the subject where it last was and i even added prints wich showed up in the output but it does nothing . I got no error,i tried changing the cancollide and anchor propretys . I even tried using the AI.
local TweenService = game:GetService("TweenService")
local Dribble = game:GetService("ReplicatedStorage"):FindFirstChild("DribbleBallForward")
local Stop = game.ReplicatedStorage:FindFirstChild("StopTween")
local who = game.Workspace.Values.Who
local sto = game.Workspace.goala.sto
Dribble.OnServerEvent:Connect(function(player, hum, Speedy, Energy,forwardVector)
local Target = Speedy.Value + ((Speedy.Value * 0.2) * 5)
local ball = game.Workspace.Ball
local meshPart = ball:FindFirstChild("MeshPart")
meshPart.Anchored = true
meshPart.CanCollide = false
if not meshPart then
return
end
-- Assuming the lookVector points forward
local targetPosition = meshPart.Position + forwardVector * Target
local tweenInfo = TweenInfo.new(3)
local tween = TweenService:Create(meshPart, tweenInfo, { Position = targetPosition })
tween:Play()
who.Value = player.Name
print(who.Value)
while true do
wait()
print("outgo")
if sto.Value == true then
print("ongoing")
tween:Pause()
tween:Destroy()
meshPart.Position = meshPart.Position
--make the tweening stop
sto.Value = false
print("mar")
end
end
wait()
meshPart.CanCollide = true
meshPart.Anchored = false
print("tween")
print("DELETE")
print("FALSE")
end)
Nothing will be shown because it gets to tween:Pause() faster than it starts tweeting. The problem it repeats might be with while true do try making it different.
I assume this is for dribbling a basketball. If the client fires the Dribble event multiple times quickly, then that could be the issue. If it does the rapid firing of the event, it creates a whole new tween and restarts the tween so quickly that even after pausing the tween, it starts another right back up and continues.
You could try adding this statement at the top of the function before anything else runs:
if sto.Value == true then return end
If the event isn’t called rapidly then there may be another issue so let me know if that’s not the case.
Also, since you’re using a while true, is this code ever reached: