Unreliable LinearVelocity effects?

I’m having trouble to get a consistent velocity using LinearVelocity. The way it’s set up is that whenever the player collides with the Launchpad part, it parents a LinearVelocity with the set attributes to the player’s character and boosts them.
The problem is, the output isn’t always the same. Sometimes, the player gets boosted properly, but sometimes the boost is little to none.

Here’s the code that takes care of it:

-- Launchpad LocalScript
local debounce = false;

local maxForce:number = self.Instance:GetAttribute("MaxForce");
local force:number = self.Instance:GetAttribute("Force");
local direction:Vector3 = self.Instance:GetAttribute("Direction");
local cooldown:number = self.Instance:GetAttribute("Cooldown");

script.Parent.Touched:Connect(function(otherPart:BasePart)
	if debounce then return; end
		
	if not otherPart.Parent then return; end
	if not otherPart.Parent:IsA("Model") then return; end
		
	local humanoid = otherPart.Parent:FindFirstChildWhichIsA("Humanoid");
	if not humanoid then return; end
		
	local rootPart = otherPart.Parent:FindFirstChild("HumanoidRootPart");
	if not rootPart then return; end
		
	local attachment = rootPart:FindFirstChild("RootAttachment");
	if not attachment then return; end
		
	-- update arguments
	maxForce = self.Instance:GetAttribute("MaxForce");
	force = self.Instance:GetAttribute("Force");
	direction = self.Instance:GetAttribute("Direction");
	cooldown = self.Instance:GetAttribute("Cooldown");
		
	local velocity:LinearVelocity = humanoid:FindFirstChildWhichIsA("LinearVelocity");
	if not velocity then
		velocity = Instance.new("LinearVelocity");
		velocity.Name = "LaunchpadVelocity";
		velocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment1;
		velocity.Attachment0 = attachment;
		velocity.Parent = humanoid;
	end

	debounce = true;

	velocity.Attachment1 = launchpadAttachment;
	velocity.VectorVelocity =  direction * force;
	velocity.MaxForce = maxForce;
	velocity.Enabled = true;
	
	-- this method isnt laggy as far as i know
	SoundSystem:PlaySFXLocal(SoundSystem:GetSoundsFolder().Movement.PlatformBounce);
		
	task.spawn(function()
		task.wait(0.2);
		velocity.Enabled = false;

		task.wait(cooldown);
		debounce = false;
	end);
end);

Here’s the SoundSystem function in case it is laggy and I just don’t know:

function SoundSystem:PlaySFXLocal(sound:Sound, onEnded:((sound:Sound)->nil)?) -- play sound locally, not on a part so it's 2D
	task.spawn(function()
		-- get sound instance
		sound = require(sound);
		local instance:Sound = self:GetSound(sound);

		-- do stuff when sound ends
		instance.Ended:Connect(function(soundId: string)
			-- if callback is set, call it
			if onEnded ~= nil then
				onEnded(sound);
			end
		end);

		if instance.IsPlaying then instance:Stop(); end
		instance:Play();
	end);
end
1 Like