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.
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
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 (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