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