Sound appearing in GetChildren table but cant be instanced?

For context,

I’m making a bumper car game and whenever the character dies the cart gets removed and replaced upon character respawn. I’m having a weird bug where I cant instance any of the children of the main part but those same instanced are appearing in a GetChildren() table. Using WaitForChild yields.

local TweenService = game:GetService("TweenService")
local repStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Storage = game:GetService("ServerStorage")

local dissolveTweenInfo = TweenInfo.new(
	1, 
	Enum.EasingStyle.Exponential,
	Enum.EasingDirection.In
)


local Forward = repStorage:WaitForChild("Forward", 5)
local Stop = repStorage:WaitForChild("Stop", 5)
local Bind = repStorage:WaitForChild("Bind", 5)

local rotationSpeed = 3
local MaxSpeed = 7
local Speed = 1

local function DissolveEffect(x, container)
	local Target = container["Part"..tostring(x)]
	Target.DecayParticle.Enabled = true
	for x = 1, 10, 1 do
		Target.Color = Color3.fromRGB(163, 162, 165)
		wait(.2 - x/50)
		Target.Color = Color3.fromRGB(255, 114, 116)
		wait(.2 - x/50)
	end
	TweenService:Create(Target, dissolveTweenInfo, {CFrame = Target.CFrame * CFrame.new(0, -70, 0)}):Play()
	wait(1)
	Target:Destroy()
end

local function Dissolve()
	local MapContainer = workspace.Map
	local Order = {}
	local count = #MapContainer:GetChildren()

	for i = 1, count, 1 do
		local generated = 0
		while true do
			generated = math.random(1, count)
			if not table.find(Order, generated) then
				table.insert(Order, generated)
				break
			end

		end
	end

	for i in pairs(Order) do
		DissolveEffect(i, MapContainer)
		wait(3)
	end
	print("complete")
end

local function Eliminate()

end

local function Colided(cart, colider)
	cart.Bump:Play()
end

local function CreateCart(Player)
	local thing = repStorage:WaitForChild("Hitbox"):Clone()
	thing.Parent = workspace
	thing.CFrame = workspace.Map.Spawner.CFrame
	thing.Name = Player.Name.."Hitbox"
	local Success, Error =  pcall(function()
		thing:WaitForChild("Character").Humanoid:ApplyDescription(Players:GetHumanoidDescriptionFromUserId(Players:GetUserIdFromNameAsync(Player.Name)))
	end)

	thing.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	

	Bind:FireClient(Player, thing)

	thing.Touched:Connect(function(colider)
		if string.find(colider.Name, "Hitbox") then
			Colided(thing, colider)
		end 
	end)

	Players.PlayerRemoving:Connect(function(leavingPlayer)
		if Player == leavingPlayer then
			thing:Destroy()
		end
	end)

	return thing
end


Players.PlayerAdded:Connect(function(Player)
	
	local killed = false
	
	Player.CharacterAdded:Connect(function(char)


		local Cart = CreateCart(Player)
		
		killed = false

		char.Humanoid.Died:Connect(function()
			Cart:Destroy()
			killed = true
		end)

		local Moving = false
		Stop.OnServerEvent:Connect(function(PlayerEvent)
			if PlayerEvent == Player then
				Moving = false
				Speed = 1
				print(Cart:GetChildren())
				Cart.Vroom.Playing = false
			end
		end)

		Forward.OnServerEvent:Connect(function(PlayerEvent)
			if PlayerEvent == Player then
				Moving = true
				Cart.Vroom.TimePosition = 1.2
				Cart.Vroom.Playing = true
			end
		end)

		while true do
			if not killed then
				if Moving == false then
					Cart.AssemblyAngularVelocity = Vector3.new(0, rotationSpeed, 0)
					wait(0.1)
				else
					Cart.AssemblyAngularVelocity = Vector3.new(0, 0, 0)
					Cart.AssemblyLinearVelocity = Cart.AssemblyLinearVelocity + (Cart.CFrame.LookVector * Speed)
					if Speed <= MaxSpeed then
						Speed = Speed + (MaxSpeed/10)
					end

					wait(0.1)
				end
			else
				break
			end
		end

		wait(10)
		Dissolve()
	end)
end)

Is this a weird roblox thing or am I just dumb ;>

1 Like

Just added a return to the Stop and Forward events if killed = true :upside_down_face:

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