Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't my dummy move with LinearVelocity?

Asked by 1 year ago

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

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

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)
0
it still did not work for some reason lolmarios2647 46 — 1y
0
Wdym I even tested it in studio myself. T3_MasterGamer 2189 — 1y
0
same bro, did not work. Where did you put the LocalScript? lolmarios2647 46 — 1y
0
I edited the answer. Just follow the instructions and it should work. T3_MasterGamer 2189 — 1y
View all comments (2 more)
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. lolmarios2647 46 — 1y
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 lolmarios2647 46 — 1y
Ad

Answer this question