The issue is, when the player's character spawns (when the player first joins the game), the code I wrapped inside of CharacterAdded won't run at all. But when my player's character respawns, everything runs just fine.
I don't think it's because the player joined before the server initializes, because I used one of my alt accounts on a different device to join an already opened server, and the results are the same.
I also don't think it's because of the code inside of CharacterAdded, I even tried
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
print("works")
end)
end)
and it still doesn't print 'works'.
If anyone thinks of what the issue is, please help me out.
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local head = char:WaitForChild("Head")
local hum = char:WaitForChild("Humanoid")
local BW = hum:WaitForChild("BodyWidthScale")
local BH = hum:WaitForChild("BodyHeightScale")
local BD = hum:WaitForChild("BodyDepthScale")
local tor = char:WaitForChild("UpperTorso")
local lhand = char:WaitForChild("LeftHand")
local rhand = char:WaitForChild("RightHand")
local lhandswing = Instance.new("Sound", lhand)
lhandswing.SoundId = "rbxassetid://138097048"
lhandswing.Name = "LeftHandSwing"
lhandswing.Volume = 2
local rhandswing = Instance.new("Sound", rhand)
rhandswing.SoundId = "rbxassetid://138097048"
rhandswing.Name = "RightHandSwing"
rhandswing.Volume = 2
hum.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
hum.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
hum.MaxHealth = hp.Value
hum.Health = hp.Value
hp.Changed:Connect(function()
hum.MaxHealth = hp.Value
hum.Health = hp.Value
end)
local randomBW = math.random(5, 30)
randomBW = randomBW / 10
BW.Value = BWSave:GetAsync(k) or randomBW
BWSave:SetAsync(k, BW.Value)
local randomBH = math.random(5, 30)
randomBH = randomBH / 10
BH.Value = BHSave:GetAsync(k) or randomBH
BHSave:SetAsync(k, BH.Value)
BD.Value = BWSave:GetAsync(k) or randomBW
BW.Changed:Connect(function()
BD.Value = BW.Value
BWSave:SetAsync(k, BW.Value)
end)
BH.Changed:Connect(function()
BHSave:SetAsync(k, BH.Value)
end)
end)
end)

1 comment
The parent argument to Instance.new() is deprecated. The parent should always be assigned last than first for better performance.