Cloning to HumanoidRootPart doesn't work

I wrote a script that’s supposed to clone ExplosionBall (in ServerStorage.BossesStuffs.Orb.OrbAttacks) to workspace, and additionally be cloned to a random character’s humanoidrootpart. I wrote this script and now I’m confused on to why it doesn’t work.

local ServerStorage = game:GetService("ServerStorage")
local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")

local explosionBall = ServerStorage.BossesStuffs.Orb.OrbAttacks.ExplosionBall:Clone()


local function spawnExplosionBall()
	
	local randomPlayer = Players:GetPlayers()[math.random(1, #Players:GetPlayers())]

	-- Check if the random player's character is valid
	if randomPlayer.Character and randomPlayer.Character:FindFirstChild("HumanoidRootPart") then
		explosionBall.Parent = Workspace
		local humanoidRootPart = randomPlayer.Character.HumanoidRootPart
		explosionBall.CFrame = CFrame.new(humanoidRootPart.Position)

	else
		print("no humanoidrootpart wdh?!")
	end
end

while true do
	spawnExplosionBall()
	wait(5)
end

I don’t know what went wrong here and am curious why it didn’t work. When playing the game, not only does it not go to the HumanoidRootPart, it doesn’t clone at all. I think I made some sort of mistake defining the random player.

You are making a Parent to workspace, just parent it to the Character, and Destroy() it after it explodes. Also, print explosionBall.CFrame, you might be suprised to see the outcome.

neither of these options changed the way the script behaves. nothing was printed, and no error was returned.

You need to clone it inside the function, and probably parent it after setting the position and possibly making a weld

Make this a reference

Instead of using the explosionBall variable make a new one that’s a clone of it

1 Like

so like… define the explosionball as a variable and then clone it?

Yes, clone it inside the function so a new one is made every time. You can also use Debris to clear it after a certain amount of time

Edit: and make sure it’s anchored

the explosionball already has all of its contents in it (e.g. the tweenservice explosion and the destroying of itself) i wont have to worry about that i think

1 Like

Maybe use the PivotTo() to move the explosionBall after you created it…

If it’s a single part they shouldn’t need to

okay really strange thing started happening, right after i started using the modified reference it gave me an error

local ServerStorage = game:GetService("ServerStorage")
local Workspace = game:GetService("Workspace")
local Players = game:GetService("Players")




local function spawnExplosionBall()
	
	local explosionBall = ServerStorage.BossesStuffs.Orb.OrbAttacks.ExplosionBall
	
	local randomPlayer = Players:GetPlayers()[math.random(1, #Players:GetPlayers())]

	-- Check if the random player's character is valid
	if randomPlayer.Character and randomPlayer.Character:FindFirstChild("HumanoidRootPart") then
		local clone = explosionBall:Clone()
		clone.Parent = Workspace
		local humanoidRootPart = randomPlayer.Character.HumanoidRootPart
		clone.CFrame = CFrame.new(humanoidRootPart.Position)
	else
		print("no humanoidrootpart wdh?!")
	end
end

while true do
	spawnExplosionBall()
	wait(5)
end

this definitely has to do with the random character

Studio does that automatically. But just add a return if the length of players equals 0 Edit: I edited this message instead of sending a new one :skull:

i am one of the players though, my player is also predefined in the players folder
image

Studio does that automatically. But just add a return if the length of players equals 0 (since it runs the function automatically which is before a player can join)

i got it working by adding like a 2 second interval, however i wont need to in the future because its gonna run while theres already players, thank you so much

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.