hello, basically I made a script that is supposed to play sounds and a gui pops up when you die, but everything except the gui works. How do I fix this?
local db = false
local Players = game:GetService("Players")
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not db then
db = true
Players.PlayerAdded:Connect(function(Player)
Player:WaitForChild("PlayerGui"):WaitForChild("DeathGui").Enabled = true
end)
game.Workspace.FirstMap.KillSound:Play()
game.Workspace.FirstMap.BassSound:Play()
hit.Parent.Humanoid.Health = 0
task.wait(7)
db = false
end
end
end)
Using the playeradded event for this makes no sense. You can just get the player from the hit parameter using GetPlayerFromCharacter()
local db = false
local Players = game:GetService("Players")
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not db then
db = true
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
plr:WaitForChild("PlayerGui"):WaitForChild("DeathGui").Enabled = true
end
game.Workspace.FirstMap.KillSound:Play()
game.Workspace.FirstMap.BassSound:Play()
hit.Parent.Humanoid.Health = 0
task.wait(7)
db = false
end
end
end)