script.Parent.Touched:Connect(function(plr)
local ui = plr:WaitForChild('PlayerGui'):WaitForChild("ScreenGui"):WaitForChild("Die")
local menu = plr:WaitForChild('PlayerGui'):WaitForChild("ScreenGui"):WaitForChild("Menu")
print("hit")
script.Parent.Gunshot:Play()
local character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid.Health = 0
ui.Visible = true
wait(0.5)
menu.Visible = true
print("everything good")
print("HOPE")
end)
located inside part
located inside workspace
located inside game
Oh oops I forgot. .Touched returns the hit, not the player the correct script would be:
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local char = hit.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local humanoid = char:FindFirstChild("Humanoid")
-- over here, I would recommend for you to use remote events to change the ui, but it doesn't really matter.
local ui = plr:WaitForChild('PlayerGui'):WaitForChild("ScreenGui"):WaitForChild("Die")
local menu = plr:WaitForChild('PlayerGui'):WaitForChild("ScreenGui"):WaitForChild("Menu")
print("hit")
script.Parent.Gunshot:Play()
humanoid.Health = 0
ui.Visible = true
wait(0.5)
menu.Visible = true
print("everything good")
print("HOPE")
end
end)
local players = game:GetService("Players")
local part = script.Parent
local gunshot = part.Gunshot
part.Touched:Connect(function(hit)
local player = players:GetPlayerFromCharacter(hit.Parent)
if player then
local character = hit.Parent
local humanoid = character.Humanoid
local playergui = player.PlayerGui
local screengui = playergui.ScreenGui
local diegui = screengui.Die
local menugui = screengui.Menu
gunshot:Play()
humanoid.Health = 0
diegui.Visible = true
task.wait(0.5)
menugui.Visible = true
end
end)