Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

1 comment

0

it is a server script, i work with FE and the character is already defined at line 7

2 answers

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.

1 comment

0

im using only r6 chars, and it isn't a Local script, i cant use local character = player.character

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

2 comments

0

using the 2nd parameter of instance.new is not advise as it negatively affects performance due to the way roblox handles property listeners

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

This discussion is preserved as it was. New answers, comments, and votes are closed.