Hey developers! I am making an attack script, but the velocity seems to work on character models, and not player characters.
The AssemblyLinearVelocity property isn’t even affected!
Example:
The script is listed below:
Attack script
local AttackRemoteEvent = game:GetService("ReplicatedStorage").RemoteEvents.Attacks -- Gets the remote event
local Settings = require(script.Settings) -- Gets attack settings
local RagdollModule = require(script.Parent.Ragdoll)
local function PlayAnimation(humanoid, id) -- Defines animation playing function
id = "rbxassetid://" .. tostring(id) -- Turns ID into a string
local anim = Instance.new("Animation") -- Creates new animation
local animator = humanoid:WaitForChild("Animator") -- Defines animator
anim.AnimationId = id -- Adds the ID to the animation
local animTrack = animator:LoadAnimation(anim) -- Loads the animation
print("Played animation ID " .. tostring(id)) -- Prints the animation ID
animTrack:Play() -- Plays the animation
animTrack:Destroy() -- Destroys the animation track
anim:Destroy() -- Destroys the animation
end
local function TemporaryRagdoll(char, t) -- Defines temporary function
RagdollModule.Ragdoll(char) -- Ragdolls player
task.wait(t) -- Waits some time
RagdollModule.Unragdoll(char) -- Unragdolls player
end
-- Gets the client fired attack
AttackRemoteEvent.OnServerEvent:Connect(function(player, attack)
attack = tostring(attack).lower(attack) -- Converts the attack into lowercase
print(player.DisplayName .. " (@" .. player.Name .. ") requested to " .. attack) -- Prints who requested an attack
local char = player.Character or player.CharacterAdded:Wait() -- Gets player character
local torso = char:WaitForChild("Torso") -- Gets player torso
if attack == "punch" then -- Checks type of attack
PlayAnimation(char:WaitForChild("Humanoid"), 123943615017025) -- Plays the animation
attackHitbox = char["Right Arm"].Touched:Connect(function(hit) -- If the arm is touched, do this
if hit.Parent ~= nil and hit.Parent:FindFirstChild("Humanoid") then
-- Define enemy parts and min / max random angular velocities, and attack window
local enemyChar = hit.Parent -- Enemy character
local enemyHumanoid = enemyChar:WaitForChild("Humanoid") -- Enemy humanoid
local enemyTorso = enemyChar:WaitForChild("Torso") -- Enemy torso
local enemyHumanoidRootPart = enemyChar:WaitForChild("HumanoidRootPart")
local minRandom = 50 -- Minimum degree of angular rotation
local maxRandom = 150 -- Maximum degree of angular rotation
enemyHumanoid.Health -= Settings[attack].damage -- Damages enemy
enemyHumanoidRootPart.AssemblyLinearVelocity = (torso.CFrame * CFrame.new(Settings[attack].direction * Settings[attack].intensity)).Position -- Sets enemy velocity
enemyHumanoidRootPart.AssemblyAngularVelocity = Vector3.new(math.random(minRandom, maxRandom), math.random(minRandom, maxRandom), math.random(minRandom, maxRandom)) -- Sets enemy angular velocity
task.spawn(TemporaryRagdoll, enemyChar, Settings[attack].ragdollTime) -- Ragdolls enemy for the amount of time
attackHitbox:Disconnect() -- Disconnects the function when ran
end
end)
task.wait(Settings[attack].attackWindow) -- The window to attack the enemy
attackHitbox:Disconnect() -- Stops attack window
end
end)