I'm trying to change a GUI when a player dies, so I have a server script detect that. Then it send the event to a local script that's supposed to then change the GUI (I want the "lives" on the GUI to decrease when the player dies). But I'm getting errors, and only the server script prints anything. I have the remote event in repstorage, and my local script is in the GUI. My server script is in serverscriptstorage or whatever.
here the code from server script
local player = game:GetService('Players').PlayerAdded:Connect(function(player)
local char = player.CharacterAdded:Connect(function(character)
local hum = character:WaitForChild("Humanoid")
local repstorage = game:GetService("ReplicatedStorage")
local DeathEvent = repstorage:WaitForChild("DeathEvent")
hum.Died:connect(function()
print("player has died! detected from server")
DeathEvent:FireClient(player)
end)
end)
end)
this is the code from my LOCAL script
local player = game:GetService('Players').PlayerAdded:Connect(function(player)
local char = player.CharacterAdded:Connect(function(character)
local hum = character:WaitForChild("Humanoid")
local DeathEvent = game.ReplicatedStorage.DeathEvent
local livestext = "lives: "
local numberoflives = 3
local lives = livestext .. numberoflives
local text = script.Parent.Text
local function deathfunction()
print("player has died! remote event worked")
text = "is it working"
end
end)
end)
DeathEvent.OnClientEvent:Connect(deathfunction)
Please explain your answers, I don't just want to get this to work, I want to learn and understand everything.
