Okay so i’m making an energy charging script for my dragon ball game and I justed wanted to know how to make the parts randomly appear around the character like this?
I’ve tried using math random like this:
while cancharge do
ki.Value += 5
local material = Character.Humanoid.FloorMaterial
local part = Instance.new("Part",Character)
part.Size = Vector3.new(.5,.5,.5)
if material then
part.Material = material
end
local newRay = Ray.new(Character.HumanoidRootPart.CFrame.p, Vector3.new(0,-1,0).unit * 10)
local Hit = game:GetService("Workspace"):FindPartOnRay(newRay, Character)
if Hit then
part.Color = Hit.Color
end
--The problem-------------------------
part.CFrame = Character.HumanoidRootPart.CFrame + Vector3.new(math.random(1,10),0,math.random(1,10))
-- the rest is not neccesary---------------
local Info = TweenInfo.new(0.2,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out,0,false,0)
local Goals = {Position = part.Position + Vector3.new(0,10,0)}
local tween = game:GetService("TweenService"):Create(part,Info,Goals)
tween:Play()
game.Debris:AddItem(part,0.6)
if player.Character.HumanoidRootPart:FindFirstChild("auracharger") == nil then
wait(0.02)
local S = Instance.new("Sound", Character.HumanoidRootPart)
S.SoundId = "rbxassetid://262498472"
S.Looped = true
S.Name = "auracharger"
S:Play()
end
print(ki.Value, maxki.Value)
if ki.Value == maxki.Value then
cancharge = false
print("cap reached")
game.ReplicatedStorage.Events.StopEnergyCharge:FireClient(player)
endcharge(player,S)
end
wait(0.2)
end
end
and then this just happens (its only spawning at that angle of the character):

