Character velocity not getting changed

so ive been trying to make it so that the player shoots up into the air, but its not quite working. heres the script

if thinginhitbox.Name == "HumanoidRootPart" and game.Players:GetPlayerFromCharacter(thinginhitbox.Parent) ~= nil then
			thinginhitbox.Parent:FindFirstChild("Humanoid"):TakeDamage(80)
			thinginhitbox.Parent:FindFirstChild("HumanoidRootPart").Velocity = thinginhitbox.Velocity + Vector3.new(0, 5000, 0)
			print(thinginhitbox.Parent.Name, "has velocity", tostring(thinginhitbox.Velocity))
			
		end

what comes out in the output is that the humanoidrootpart DOES have velocity (which immedeately gets set to 0), buut the character doesnt actually go up
maybe its cuz its a serverscript but i dunno. any help is appreciated plz
i have tried looking for other solutions on the devforum but all of them just use bodyforce which is now deprecated
also tried using remotevents to make it so that the velocity is changed from a localscript, did not work

meh im probably just gonna use bodyforce even tho its deprecated.

Maybe a pinch late but this should work.

Below is an inner part of a Script in my ServerScriptsService folder that connects an annonymous function to the Touched event for any parts in located in a certain folder (not shown). This makes any parts in the specified folder act as a launch pad in this case, flinging the player upwards along the world Y axis.

When the part is touched the Touch event fires, it verifies that what touched it was a player, creates an instance of LinearVelocity and an attachment which connects the HumanoidRootPart of the player to the instance of LinearVelociy, once attached the player gets launched and then the Linear Velocity and Attachment are removed. Player regains control and begins to fall down.

The trick with using LinearVelocity is first off it’s an instance, not a property so you can’t just set it, from what I can see the players AssemblyLinearVelocity is read only, you need a force instance of one kind or another to apply a force to the player. That along with having to “interconnect” the LV instance to an attachment which is attached to the HRP of the player, it feels like more than what should be required but once connected it all works as expected from what I can see and it’s not much more to create the LV instance.

Not sure how well it would scale i.e. multiple users touching the same part at once and possibly “jamming things up” on the server breifly but it’s not that much work for the server so it may be fine.

Hope this helps.

local HRP = TouchingPart.Parent:FindFirstChild("HumanoidRootPart") --if the touching part has HRP they are a player
if HRP then 
	local LV = Instance.new("LinearVelocity") --create new instance of LV
	local Attach = Instance.new("Attachment") --create a new attachment
	Attach.Parent = HRP --connect the attachment to the HRP
	LV.Attachment0 = Attach --connect the attachment to slot 0 on the LV instance
	LV.MaxForce = 20000 --Could be Math.huge, should be at least over 5000 
	LV.VectorVelocity = Vector3.new(0, 200, 0) --Direction of travel in world space
	LV.Parent = Attach --Parent the attachment to the LV, player starts moving now
	task.wait() -- Wait a little bit
	LV:Destroy() --Destroy the LV instance
	Attach:Destroy() --Destroy the attachment, player back in control
end

thanks for the reply, ill try it a bit later!!

aand nope, it did not work.
sorry for the quite late reply lol
anyway imma just use bodyforce

ive ended up using vectorforce. heres the code for anyone checking this post

if thinginhitbox.Name == "HumanoidRootPart" and game.Players:GetPlayerFromCharacter(thinginhitbox.Parent) ~= nil then
		local vel = Instance.new("VectorForce")
		local attach = Instance.new("Attachment", thinginhitbox)

		vel.Force = Vector3.new(0, 10000, 0)
		vel.Attachment0 = attach
		vel.Parent = thinginhitbox
		task.wait(.1)
		vel:Destroy()
		attach:Destroy()
end
1 Like

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