How to make parts randomly appear around the player?

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):

I tried it but still does the same thing

ok so, the parts are spawning at the same y level as the humanoid root part, then its is going up cause of the tween, put a -3 on the Y axis
part.CFrame = Character.HumanoidRootPart.CFrame:ToWorldSpace(CFrame.new(math.random(1,10), -3 or something, math.random(1,10))

i dont speak english, dont judge me :laughing:

the problem is the direction, not the height

math.random(1,10)

From what I’ve seen right there the problem is that the random range does not cover all of the side if you know what I mean.

Try using -10 and 10 instead of 1 and 10 so it does cover the player’s entire character range thingy.

math.random(-10, 10)
-- Fixed line
part.CFrame = Character.HumanoidRootPart.CFrame + Vector3.new(math.random(-10,10),0,math.random(-10,10))

1 Like