Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why won't my dummy move with LinearVelocity?

So, I am trying to create a combat system, and I am currently experimenting with some things. I want to make a script that basically knocks up the nearest player (did not implement that yet, i am still experimenting) and i already ran into some issues.

local dummy = game.Workspace.Dummy
local dHum = dummy:FindFirstChild("Humanoid")
local dHRP = dummy:FindFirstChild("HumanoidRootPart")

local UIS = game:GetService("UserInputService")
local deb = false

UIS.InputBegan:Connect(function(input, gpe)    
    if gpe then return end
    
    if input.KeyCode == Enum.KeyCode.Q and not deb then
        deb = true
        
        dHum.WalkSpeed = 0
        dHum.JumpPower = 0
        
        local v = Instance.new("LinearVelocity", dHRP)
        v.MaxForce = 99999999
        
        v.VectorVelocity = Vector3.new(0,10,0)
        
        game.Debris:AddItem(v,0.3)
        
        wait(5)
        deb = false
    end         
end)

basically I add a linearvelocity to the dummy's HumanoidRootPart, and so i thought to myself "This should move the dummy upwards, right?"

Welp, i was not right, please help

1 answer

✓ Accepted answer

You forgot to set Attachment0.

Also when setting an NPC's velocity, always do it in a server script. To achieve that, you must use a RemoteEvent. It must be parented to ReplicatedStorage and named DummyVelocity.

LocalScript in StarterPlayerScripts or StarterGui:

local RS = game:GetService("ReplicatedStorage")
local RE = RS:WaitForChild("DummyVelocity")
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, gpe)    
	if gpe then return end
	if input.KeyCode == Enum.KeyCode.Q then
		RE:FireServer()
	end
end)

Script inside the dummy's HumanoidRootPart.

local dHRP = script.Parent
local dummy = dHRP.Parent
local dHum = dummy:FindFirstChildOfClass("Humanoid")

local RS = game:GetService("ReplicatedStorage")
local RE = RS.DummyVelocity
local Debris = game:GetService("Debris")
local deb = false

RE.OnServerEvent:Connect(function()
	if not deb then
		deb = true
		
		dHum.WalkSpeed = 0
		dHum.JumpPower = 0
		
		local v = Instance.new("LinearVelocity", dHRP)
		local attach = Instance.new("Attachment", dHRP) -- solution
		v.Attachment0 = attach -- solution
		v.MaxForce = math.huge
		v.VectorVelocity = Vector3.new(0, 10, 0)
		
		Debris:AddItem(v, 0.3)
		Debris:AddItem(attach, 0.3)
		
		task.wait(5)
		dHum.WalkSpeed = 16
		dHum.JumpPower = 50
		deb = false
	end
end)

6 comments

0

it still did not work for some reason

0

Wdym I even tested it in studio myself.

0

same bro, did not work. Where did you put the LocalScript?

0

I edited the answer. Just follow the instructions and it should work.

0

bro i am not even kidding you, it's still not working. I followed the instructions word to word and it'sstill not working. If you have discord i can show you there.

0

nevermind, it worked, for some reason i tested it twice, with the first time having no errors at all and it still did not work, but it worked now so thank you, i appreciate the help

This discussion is preserved as it was. New answers, comments, and votes are closed.