Why does my script not work?

Hello! So I am trying to make the player a giant black hole whenever they join the game, but for some reason, it looks like this:
image
Can someone please tell me why?

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

function SetupPlayer(Player)
	for _, v in pairs(Player.Character:GetChildren()) do
		if v.ClassName == "MeshPart" then
			v.Transparency = 1
		elseif v.ClassName == "Accessory" then
			v:Destroy()
		end
		
		if v.Name == "Head" then
			v.face:Destroy()
		end
	end
	
	local Hole = ReplicatedStorage.Hole:Clone()
	Hole.Parent = game.Workspace
	Hole.Name = Player.Name .. "'s Hole"
	
	local Weld = Instance.new("WeldConstraint")
	Weld.Parent = Hole
	Weld.Part0 = Hole
	Weld.Part1 = Player.Character.HumanoidRootPart
	
	while (Player.Character == nil) or (Player.Character.HumanoidRootPart == nil) do
		task.wait(1)
	end
end

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		SetupPlayer(Player)
		Character.Humanoid.UseJumpPower = true
		Character.Humanoid.JumpPower = 0
	end)

If you think you know what went wrong, please let me know. Thank you and have a wonderful day! :slight_smile:

7 Likes

set the holes position to the humanoidrootpart before welding

3 Likes

It worked! But why do my head and waist accessories still appear?
image

1 Like

when checking if its an accessory try destroying the handle ( v.Handle:Destroy() )not the accessory itself

1 Like

Like this?

function SetupPlayer(Player)
	for _, v in pairs(Player.Character:GetChildren()) do
		if v.ClassName == "MeshPart" then
			v.Transparency = 1
		elseif v.ClassName == "Accessory" then
			v.Handle:Destroy()
		end
		
		if v.Name == "Head" then
			v.face:Destroy()
		end
	end

yes ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

2 Likes

Because for some reason it does not work.
Full script:

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

function SetupPlayer(Player)
	for _, v in pairs(Player.Character:GetChildren()) do
		if v.ClassName == "MeshPart" then
			v.Transparency = 1
		elseif v.ClassName == "Accessory" then
			v.Handle:Destroy()
		end
		
		if v.Name == "Head" then
			v.face:Destroy()
		end
	end
	
	local Hole = ReplicatedStorage.Hole:Clone()
	Hole.Parent = game.Workspace
	Hole.Name = Player.Name .. "'s Hole"
	Hole.Position = Player.Character.HumanoidRootPart.Position
	
	local Weld = Instance.new("WeldConstraint")
	Weld.Parent = Hole
	Weld.Part0 = Hole
	Weld.Part1 = Player.Character.HumanoidRootPart
	
	Hole.Eating.Changed:Connect(function(Val)
		if Val == true then
			task.wait()
			Hole.Eating.Value = true
		end
	end)
	
	Hole.Touched:Connect(function(Toucher)
		if Toucher.Parent == workspace.Stuff and Hole.Eating.Value == false then
			Hole.Eating.Value = true
			Toucher.CFrame = CFrame.new(Toucher.Position, Hole.Position)
			Toucher.Velocity = Toucher.CFrame.LookVector * 35
			Toucher.Anchored = false
			
			Hole.EatingSound.TimePosition = 0
			Hole.EatingSound.Playing = true
			task.wait(0.35)
			Toucher:Destroy()
			Hole.Size += Vector3.new(0, 2, 0)
			
		elseif string.find(Toucher.Name, "Hole") ~= nil then
			if Toucher.Size.Y > Hole.Size.Y then
				
				local Explosion = Instance.new("Explosion", workspace)
				Explosion.Position = Hole.Position
				Explosion.BlastRadius = 100
				Explosion.BlastPressure = 100
				task.wait()
				Hole:Destroy()
				Player.Character.Humanoid.Health = 0
			end
		end
	end)
	
	while (Player.Character == nil) or (Player.Character.HumanoidRootPart == nil) do
		task.wait(1)
	end
end

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		SetupPlayer(Player)
		Character.Humanoid.UseJumpPower = true
		Character.Humanoid.JumpPower = 0
	end)
	
	while task.wait(1) do
		for _, Player in pairs(Players:GetPlayers()) do
			if Player.Character then
				Player.Character.Humanoid.JumpPower += 1
			end
		end
	end
	
	for _, Player in pairs(Players:GetPlayers()) do
		if Player.UserId == 3081295884 then
			print("wolf")
		end
	end
end)
1 Like

Does anyone know why this does not work?

2 Likes

Heya @Kittylitterking123!

I took a look at your script and it seemed that there were a few parts that did not need to be included, so I decided to remake everything with a simple code to understand.

The code was made in the Workspace because at StarterPlayer > StarterPlayerScripts or StarterCharacterScripts it is not working, independent of being a LocalScript or a Script, but at Workspace, it is working fine:

local Players = game:GetService( "Players" )

local ReplicatedStorage = game.ReplicatedStorage

local Folder = ReplicatedStorage.Folder

for _, value in Folder:GetDescendants() do
	
	if value:IsA( "Part" ) and value.Name == "Hole" then
		
		Black_Hole = value
		
		print( true )
		
	end	
		
end

Black_Hole_Clone = Black_Hole:Clone()
Black_Hole_Clone.Parent = game.Workspace
Black_Hole_Clone.CanCollide = false
Black_Hole_Clone.CanQuery = false
Black_Hole_Clone.CanTouch = false

local WeldConstraint = Instance.new( "WeldConstraint", Black_Hole_Clone )

local NoCollisionConstraint = Instance.new( "NoCollisionConstraint", Black_Hole_Clone)

Players.PlayerAdded:Connect(function( Player )
	
	print( Player.Name, true )
	
	local Character = Player.Character or Player.CharacterAdded:Wait()
	
	local Humanoid = Character:FindFirstChildWhichIsA( "Humanoid" )
	
	Player.CharacterAppearanceLoaded:Connect(function()
		
		for _, value in pairs( Character:GetDescendants() ) do
			
			print( value )
			
			if value.ClassName == "MeshPart" then
				
				value.Transparency = 1
				
			end
			
			if value.Name == "Head" then
				
				print( value.Name )
				
				local Head = value
				
				for _, value2 in pairs( Head:GetDescendants() ) do
					
					if value2.Name == "face" then
						
						value2:Destroy()
						
						print( value2 )
						
					end
					
				end
				
			end
			
			if value.Name == "HumanoidRootPart" then
				
				print( value.Name )
				
				Black_Hole_Clone.Parent = value
				
				WeldConstraint.Part0 = Black_Hole_Clone
				WeldConstraint.Part1 = value
				
				NoCollisionConstraint.Part0 = Black_Hole_Clone
				NoCollisionConstraint.Part1 = value
				
			end
			
		end
		
		Humanoid.UseJumpPower = true
		
		if Humanoid.UseJumpPower == true then
			
			Humanoid.JumpPower = 0
			
			print( Humanoid.JumpPower )
			
		elseif Humanoid.UseJumpPower == false then
			
			Humanoid.JumpHeight = 0
			
			print( Humanoid.JumpHeight )
			
		end
		
	end)
	
end)

Let me know if it works, @Kittylitterking123! :grin:

1 Like

Use a Weld instead of a weld constraint, that would let you not need to bring its position to the hrp

1 Like

Sadly it didn’t work. It turns the player’s character invisible and spams my output with this error I’ve never seen before.

What all do I need to set for the Weld? I’m not used to welding instances through scripts lol.

This part where it spams errors in the Output/Developer Console is part of a Roblox Engine bug:

Furthermore, related to the script, there are a few things that I would like to mention as well that I missed:

  1. You need to create a Folder in ReplicatedStorage.
  2. You need to insert the mesh “black hole” into the Folder.
  3. Make sure both Position and CFrame are -0.5 (X), 1 (Y), 0 (Z)
  4. Change the name from “black hole” → “Hole”.

Believe this should explain better. Tell me if that works by sharing a photo and/or a video! :smile:

1 Like

A weld is a weld constraint without the offset.

1 Like

I did the steps you provided, but it didn’t do anything.

I made the blackhole which is just a squashed-down cylinder part I put into a Folder in RS.
I set the position and CFrame to the correct coordinates.
image
I also changed the name of BlackHole to Hole in my server script.

Did I do anything wrong?

After over a year, I FINALLY fixed this script! I had to completely change how I went about some of it and still have no idea why the original didn’t work, but at least it’s fixed now!

Here is the new script for anyone dealing with similar issues:

local PartsToHide = {
		"Head",
		"LeftFoot",
		"LeftHand",
		"LeftLowerArm",
		"LeftLowerLeg",
		"LeftUpperArm",
		"LeftUpperLeg",
		"LowerTorso",
		"RightFoot",
		"RightHand",
		"RightLowerArm",
		"RightLowerLeg",
		"RightUpperArm",
		"RightUpperLeg",
		"UpperTorso",
}

local function SetupPlayer(Player:Player)
	local Character: Model = Player.Character or Player.CharacterAdded:Wait()
	
	for _, v in pairs(Character:GetChildren()) do
		if v:IsA("MeshPart") and v.Name == "Head" then
			print("YES")
			local face:Decal = v.face
			
			if face then
				print("EXISTS")
				face:Destroy()
			end	
			print("HI")
		elseif v:IsA("Accessory") and v:FindFirstChild("Handle") then
			v.Handle.Transparency = 1
		end
	end
	
	local HumanoidRootPart:BasePart = Character:WaitForChild("HumanoidRootPart")
	
	if Character and HumanoidRootPart then
		local Hole = game.ReplicatedStorage.Hole:Clone()
		Hole.Name = Player.Name
		Hole.Position = HumanoidRootPart.Position
		Hole.Parent = workspace
		
		local Weld = Instance.new("WeldConstraint")
		Weld.Part0 = HumanoidRootPart
		Weld.Part1 = Hole
		Weld.Parent = Hole
	end
	
	for _, PartName in pairs(PartsToHide) do
		local Part = Character:WaitForChild(PartName)
		Part.Transparency = 1
	end
end

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAppearanceLoaded:Connect(function(Character)
		SetupPlayer(Player)
		local Humanoid = Character:FindFirstChildOfClass("Humanoid")
		Humanoid.UseJumpPower = true
		Humanoid.JumpPower = 0
	end)
end)

Thank you to everyone who helped me with this and have a wonderful day! :slight_smile:

1 Like

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