ApplyImpulse() Not always working?

Hello, So I have been working on a throwable chair and it works and all but sometimes the ApplyImpulse() doesn’t work.

–Here is the ApplyImpulse() Part in script

	local Direction = Hum.CFrame.LookVector
		local forceMultipliter = 50 * Parent:GetMass()
		Parent:ApplyImpulse(Direction * forceMultipliter)

If you want to see the full script or any more information just ask.

What do you mean by “sometimes”? Are you sure the direction and force is sufficient?

What have you researched?

Have you looked at these other posts?

Keywords, Network Ownership, client and server.

Therefore you will also need to post more information regarding if the script is client or server.

1 Like

When I trigger the function sometimes it gets shot in the direction I want and then sometimes it just falls on the players head.

1 Like

It is a server script.
Hang on Ill get you the whole script.

I don’t think this is the issue, as stated the code does sometimes work. It would be good to check though.

--Objects
local Parent = script.Parent
local Prompt = Parent:FindFirstChild("ThrowChairPrompt")
local Chair = Parent.Parent

local BadgeService = game:GetService("BadgeService")

--Values
local IsThrowing = false
local animationId = 12647936621
local Rotation = CFrame.Angles(45,0,0)
local animation = Instance.new("Animation")
animation.AnimationId = 'rbxassetid://' .. animationId

local BadgeId = 2141870924

--Functions
Prompt.Triggered:Connect(function(plr)
	if not IsThrowing then
		IsThrowing = true
		Prompt.Enabled = false
		local RightArm = plr.Character:FindFirstChild("Right Arm")
		Chair:SetPrimaryPartCFrame(RightArm.CFrame)
		
		for i, z in pairs(Chair:GetChildren()) do
			if z:IsA("BasePart") then
				z.CanCollide = false
			end
		end
		
		local Weld = Instance.new("Weld")
		Weld.Parent = RightArm
		Weld.Part0 = RightArm
		Weld.Part1 = Chair.PrimaryPart
		
		local humanoid = plr.Character:FindFirstChild("Humanoid")
		local animationTrack = humanoid:WaitForChild("Animator"):LoadAnimation(animation):Play()
		wait(0.8)
		Weld:Destroy()
		local Hum = plr.Character:FindFirstChild("HumanoidRootPart")
		script.Parent.CFrame = Hum.CFrame * CFrame.new(0,6,0) * Rotation
		local Direction = Hum.CFrame.LookVector
		local forceMultipliter = 50 * Parent:GetMass()
		Parent:ApplyImpulse(Direction * forceMultipliter)
		wait(0.125)
		for i, z in pairs(Chair:GetChildren()) do
			if z:IsA("BasePart") then
				z.CanCollide = true
			end
		end
		
		local Chance = math.random(1,100)
		if Chance == 37 then
			wait(2)
			local Explosion = Instance.new("Explosion")
			Explosion.Parent = Parent
			Explosion.Position = Parent.Position
			print("What just happend?")
			BadgeService:AwardBadge(plr.UserId, BadgeId)
		end
		
		IsThrowing = false
		Prompt.Enabled = true
	end
end)

This could mean that the mass isn’t sufficient, try printing Parent:GetMass() before applying the impulse.

Just looked on the docs, you should be using .Mass as :GetMass() is only for backwards compatibility.
https://create.roblox.com/docs/reference/engine/classes/BasePart#GetMass

ApplyImpulse being called on a client-owned part with a server-script will still work.
https://create.roblox.com/docs/reference/engine/classes/BasePart#ApplyImpulse

2 Likes

I tried printing it and every time I threw it the mass was 14 even the times it didn’t work.

Just tried .Mass and It sadly had the same result as before.

Interesting, with the documentation thanks for showing me.

Unfortunately testing shows otherwise.

Applying impulse on server on part with serverscript.

local part = script.Parent


--task.spawn(function()
	
--	while true do
--		local player = game.Players:FindFirstChildOfClass("Player")
--		print(player)
--		if player then
--			part:SetNetworkOwner(player)
--			end
--		task.wait(1)
--	end
--end)
while true do
	part:ApplyImpulse(Vector3.yAxis*part:getMass()*100)
	task.wait(1)
end

If you set the network owner to client

local part = script.Parent


task.spawn(function()
	
	while true do
		local player = game.Players:FindFirstChildOfClass("Player")
		print(player)
		if player then
			print("Setting network owner", player)
			part:SetNetworkOwner(player)
			end
		task.wait(1)
	end
end)
while true do
	part:ApplyImpulse(Vector3.yAxis*part:getMass()*100)
	task.wait(1)
end

It will not jump anymore, once you delete the player instance on the server it will then apply all at once and go to the server. I believe this is what is happening to @BrokenV0id scenario.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.