You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I would like to push a the player towards their mouse direction but don’t know how to push them
This is the script i have going so far below, the variables are
Char = Character
hitpos = mouse.hit.position
hp = hit power (variable from 1 to 100 of how long the player held the mouse down for)
local lv = CFrame.new(char.HumanoidRootPart.Position * hitpos * hp).LookVector
local imp = char.HumanoidRootPart:ApplyImpulse(lv)
game:GetService("Debris"):AddItem(imp, hp/33)
You can use Suphi’s method of getting the mouse position in the workspace.
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character
local HumanoidRootPart: Part = Character:WaitForChild("HumanoidRootPart")
local hitPower = 50
-- returns a direction
local function Direction(From: Vector3, To: Vector3)
return (To - From).Unit
end
-- returns the mouse position in the workspace
local function Raycast()
local mouse = game:GetService("UserInputService"):GetMouseLocation()
local ray = workspace.CurrentCamera:ViewportPointToRay(mouse.X, mouse.Y)
local result = workspace:Raycast(ray.Origin, ray.Direction * 100, RaycastParams.new())
if result == nil then
return ray.Origin + ray.Direction * 100
else
return result.Position, result.Instance
end
end
-- returns the model mass/weight
function getMass(model)
assert(model and model:IsA("Model"), "Model argument of getMass must be a model.");
local mass = 0;
for i,v in pairs(model:GetDescendants()) do
if(v:IsA("BasePart")) then
mass += v:GetMass();
end
end
return mass;
end
while true do
local direction = Direction(Character:GetPivot().Position, Raycast()) * hitPower * getMass(Character)
HumanoidRootPart.AssemblyLinearVelocity = direction -- overrides the current velocity, If you don't want it to overwrite use +=
--local Part = Instance.new('Part')
--Part.CFrame = Character:GetPivot()
--Part.Anchored = false
--Part.CanCollide = false
--Part.Size = Vector3.one
--Part.Shape = Enum.PartType.Ball
--Part.Transparency = 0.5
--Part.Parent = workspace
--Part.AssemblyLinearVelocity = direction
task.wait(5)
end
Try to give details about why this script isn’t working, what you want it to do, and (if it is relevant) what you are doing differently to make it work
This is my first time trying to do something like this and i have no idea how to code it but i think it should be like this
local lv = CFrame.new(char.HumanoidRootPart.Position * hitpos * hp).LookVector
local imp = char.HumanoidRootPart:ApplyImpulse(lv)
game:GetService(“Debris”):AddItem(imp, hp/33)
If you have any code to share, please post it in a code block!