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

How I can resolve my problem with a part that don't move when i use bodi velocity?

So I am trying to make a script that when you press a key it will make a fireball that moves, but the problem is that when I press the key the ball just appear and don't move.I used bodyvelocity to move it!

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Mouse = Player:GetMouse()
local debounce = false


Mouse.KeyDown:connect(function(key)
	key = key:lower()
	if key == "q" and debounce == false then	
		fireball = Instance.new('Part')
		fireball.Parent = Player.Character
		fireball.BrickColor = BrickColor.new("Deep orange")
		fireball.Shape = "Ball"
		fireball.Material = "Neon"
		fireball.CFrame = Character.Torso.CFrame * CFrame.new(0,0,-5)
		bv = Instance.new("BodyVelocity")
		
		bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		bv.Velocity = Character.Torso.CFrame.lookVector*20
		bv.Parent = fireball
	end
end)



1 answer

✓ Accepted answer

Hey man, this one was a bit of a challenge to figure out and I'm not totally satisfied with the result but it works! After debugging the issue seemed to be making the PartType a ball. The solution to this is to make it a normal part and put a ball mesh into it. See the completed code below.

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Mouse = Player:GetMouse()
local debounce = false

Mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "q" and debounce == false then   
		-- Create fire ball mesh
		local specialmesh = Instance.new('SpecialMesh')
		specialmesh.MeshType = Enum.MeshType.Sphere
		-- Create fire ball
        local fireball = Instance.new('Part')
        fireball.Parent = Player.Character
        fireball.BrickColor = BrickColor.new("Deep orange")
        fireball.Shape = Enum.PartType.Block
      	fireball.Material = Enum.Material.Neon
		fireball.Size = Vector3.new(3, 3, 3)
		-- Parent the sphere mesh into the part
		specialmesh.Parent = fireball
		-- Create a bodyvelocity
        local bv = Instance.new("BodyVelocity")
        bv.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
        bv.Velocity = Character.Torso.CFrame.lookVector*20
        bv.Parent = fireball
		-- Position fire ball
        fireball.CFrame = Character.Torso.CFrame * CFrame.new(0,0,-5)
    end
end)

P.S Look into using Enum items rather than strings for cleaner code :)

1 comment

0

Hm... Good thx

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