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

Body Velocity to a direction that my torso is facing (including Y position)?

Asked by 5 years ago
Edited 5 years ago

with my script i create a sphere with a body velocity, his X position and Z position works very well, but Y position doesn't work, i already created a script that move my torso to the direction that im clicking, but the body velocity still not working, somebody can help me?

local rs = game:GetService("ReplicatedStorage")
local event = Instance.new("RemoteEvent", rs)
event.Name = "GenkiDama"


local function FiredEvent(player)
    local character = game.Workspace:WaitForChild(player.Name)
    wait(.1)
    local ki = Instance.new("Part")
    ki.Size = Vector3.new(40,40,40)
    ki.Size = ki.Size+Vector3.new(.42,.42,.42)
    ki.Shape = "Ball"
    ki.Name = "Energy"
    ki.CanCollide = false
    ki.BrickColor = BrickColor.new("Cyan")
    ki.Material = "Neon"
    ki.Parent = character
    ki.CFrame = character.HumanoidRootPart.CFrame*CFrame.new(0,0,-45)
    ki.CFrame = character.Torso.CFrame*CFrame.new(1, 1, -3)
    local bv = Instance.new("BodyVelocity", ki)
    bv.maxForce = Vector3.new(math.huge, math.huge, math.huge)
    bv.velocity = character.HumanoidRootPart.CFrame.lookVector*120

    game.Debris:AddItem(ki, 9)
    local sound = Instance.new("Sound")
    sound.SoundId = "rbxassetid://586187912"
    sound.Parent = ki
    sound:Play()
    wait(0.2)
    local dmg = script.Damage:Clone()
    dmg.Parent = ki

end

event.OnServerEvent:Connect(FiredEvent)
0
it is a server script, i work with FE and the character is already defined at line 7 darkzerobits 92 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

I think it isn't working because of the 'bv.velocity' needing to have a capital V, as referencing things in Lua is case-sensitive.

You should also set the P property of the body velocity to something high if the ball goes through the ground when you spawn it.

On a side note, you can reference character by just doing

local character = player.Character

Also, the script will error at line 19 if you're using r15 characters, which you're probably not.

0
im using only r6 chars, and it isn't a Local script, i cant use local character = player.character darkzerobits 92 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

On Line 21, bv.maxForce needs to become bv.MaxForce and on Line 22 bv.velocity needs to become bv.Velocity since otherwise, you are not properly referencing the Properties of "bv"

Revised:

local rs = game:GetService("ReplicatedStorage")
local event = Instance.new("RemoteEvent", rs)
event.Name = "GenkiDama"

local function FiredEvent(player)
    local character = game.Workspace:WaitForChild(player.Name)
    wait(.1)
    local ki = Instance.new("Part", character)
    ki.Size = Vector3.new(40,40,40)
    ki.Size = ki.Size + Vector3.new(.42,.42,.42)
    ki.Shape = "Ball"
    ki.Name = "Energy"
    ki.CanCollide = false
    ki.BrickColor = BrickColor.new("Cyan")
    ki.Material = "Neon"
    ki.CFrame = character.HumanoidRootPart.CFrame*CFrame.new(0,0,-45)
    ki.CFrame = character.Torso.CFrame*CFrame.new(1, 1, -3)
    local bv = Instance.new("BodyVelocity", ki)
    bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    bv.Velocity = character.Torso.CFrame.lookVector*60

    game.Debris:AddItem(ki, 9)
    local sound = Instance.new("Sound", ki)
    sound.SoundId = "rbxassetid://586187912"
    sound:Play()
    wait(0.2)
    local dmg = script.Damage:Clone()
    dmg.Parent = ki

end

event.OnServerEvent:Connect(FiredEvent)

Also, when you create a new instance, you can set the Parent of the Instance without having to add another line of code by simply changing

    local sound = Instance.new("Sound")
    sound.Parent = ki

to

    local sound = Instance.new("Sound", ki)

The only other possible error after this is to make sure that the script.Damage is not nil

0
using the 2nd parameter of instance.new is not advise as it negatively affects performance due to the way roblox handles property listeners theking48989987 2147 — 5y
0
my scripts works very well, the problem is only BodyVelocity isn't detecting Y position using LookVector, there is no errors in the other things, the ONLY problem is Y position darkzerobits 92 — 5y

Answer this question