-
What do you want to achieve?
Permanent death screen. -
What is the issue?
I want to make server to client event, but it doesn’t fire. -
What solutions have you tried so far?
I looked at YouTube, DevForum and DevHub.
(I deleted some lines in scripts to make it more clear)
Script in StarterPlayerScripts:
repeat wait() until game:IsLoaded()
hum.Died:Connect(function()
replicatedStorage.Remotes.Died:FireServer(client)
Death:Died(client)
end)
replicatedStorage.Remotes.CheckDeath.OnClientEvent:Connect(function(client)
Death:Died(client)
end)
Module script:
local Death = {
ts_time = 1
}
Death.Died = function(x, client)
local deathui = replicatedStorage.Others.Death:Clone()
deathui.Parent = client:WaitForChild("PlayerGui")
replicatedStorage.Remotes.Died:FireServer(client)
client:WaitForChild("PlayerGui").Sounds.Died:Play()
cam.CameraType = Enum.CameraType.Scriptable
while wait() do
deathui.Enabled = true
deathui.ResetOnSpawn = false
deathui.IgnoreGuiInset = true
end
end
return Death
Script in ServerScriptService:
--game.Players.CharacterAutoLoads is set to false
clients.PlayerAdded:Connect(function(client)
local dead = Instance.new("BoolValue")
dead.Name = "Dead"
dead.Parent = client
dead.Value = mainStorage:GetAsync(client.UserId) or false
replicatedStorage.Remotes.Joined.OnServerEvent:Connect(function()
print(dead.Value)
if dead.Value == true then
replicatedStorage.Remotes.CheckDeath:FireClient(client) --this event is not firing, event though there are no errors in output
elseif dead.Value == false then
client:LoadCharacter()
end
end)
end)
game.Players.PlayerRemoving:Connect(function(client)
mainStorage:SetAsync(client.UserId, client:FindFirstChild("Dead").Value)
end)
replicatedStorage.Remotes.Died.OnServerEvent:Connect(function(client)
client:FindFirstChild("Dead").Value = true
end)
(Sorry for mistakes (if there are any), English is not my national language.)