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
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)