Hello everyone,
I made this script, and I’ts not detecting the player’s primary part. I tried to use repeat, but it says attempt to index nil with FindFirstChild…
game.Players.PlayerAdded:Connect(function(player)
if player.Character:FindFirstChild("HumanoidRootPart") then
local folder = Instance.new("Folder", player)
folder.Name = "Music"
local sound = Instance.new("StringValue", folder)
sound.Name = "SoundID"
sound.Value = "0"
local dp = Instance.new("StringValue", folder)
dp.Name = "DeathID"
dp.Value = "0"
local audio = Instance.new("Sound", player.Character:FindFirstChild("HumanoidRootPart"))
audio.SoundId = sound.Value
audio.Name = "MusicSound"
audio.Volume = 1
audio.Looped = true
player.Character.PrimaryPart:FindFirstChild("Died").SoundId = dp.Value
sound:GetPropertyChangedSignal("Value"):Connect(function()
audio.SoundId = sound.Value
end)
dp:GetPropertyChangedSignal("Value"):Connect(function()
player.Character:FindFirstChild("HumanoidRootPart"):FindFirstChild("Died").SoundId = dp.Value
end)
end
end)