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.
01 | local dummy = game.Workspace.Dummy |
02 | local dHum = dummy:FindFirstChild( "Humanoid" ) |
03 | local dHRP = dummy:FindFirstChild( "HumanoidRootPart" ) |
04 |
05 | local UIS = game:GetService( "UserInputService" ) |
06 | local deb = false |
07 |
08 | UIS.InputBegan:Connect( function (input, gpe) |
09 | if gpe then return end |
10 |
11 | if input.KeyCode = = Enum.KeyCode.Q and not deb then |
12 | deb = true |
13 |
14 | dHum.WalkSpeed = 0 |
15 | dHum.JumpPower = 0 |
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
:
01 | local RS = game:GetService( "ReplicatedStorage" ) |
02 | local RE = RS:WaitForChild( "DummyVelocity" ) |
03 | local UIS = game:GetService( "UserInputService" ) |
04 |
05 | UIS.InputBegan:Connect( function (input, gpe) |
06 | if gpe then return end |
07 | if input.KeyCode = = Enum.KeyCode.Q then |
08 | RE:FireServer() |
09 | end |
10 | end ) |
Script
inside the dummy's HumanoidRootPart.
01 | local dHRP = script.Parent |
02 | local dummy = dHRP.Parent |
03 | local dHum = dummy:FindFirstChildOfClass( "Humanoid" ) |
04 |
05 | local RS = game:GetService( "ReplicatedStorage" ) |
06 | local RE = RS.DummyVelocity |
07 | local Debris = game:GetService( "Debris" ) |
08 | local deb = false |
09 |
10 | RE.OnServerEvent:Connect( function () |
11 | if not deb then |
12 | deb = true |
13 |
14 | dHum.WalkSpeed = 0 |
15 | dHum.JumpPower = 0 |