Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I do global chat message deaths?

Asked by 5 years ago

Forgive me if I'm an idiot, and my code is messy.

I tried using a LocalScript inside of StarterCharacterScripts that uses math.random(1,3) to choose a death message, which worked, but I wasn't satisfied with it, as the death messages are local.

How would I go about doing global randomized death messages? I was thinking of using a RemoteEvent for a server-sided Script. Would that work? Is there a much simpler option that I'm not seeing?

LocalScript inside of StarterCharacterScripts:

game.Players.LocalPlayer.Character.Humanoid.Died:Connect(function()
    local mr = math.random(1,3)
    local red = BrickColor.new('Bright red')
    local deadPlayer = game.Players.LocalPlayer.Character.Name

    if mr == 1 then
        game.StarterGui:SetCore("ChatMakeSystemMessage", {
            Text = deadPlayer.. " tripped!";
            Font = Enum.Font.Highway;
            Color = red.Color;
            FontSize = Enum.FontSize.Size96;
        })
    end

    if mr == 2 then
        game.StarterGui:SetCore("ChatMakeSystemMessage", {
            Text = deadPlayer.. " stepped on a landmine!";
            Font = Enum.Font.Highway;
            Color = red.Color;
            FontSize = Enum.FontSize.Size96;
        })
    end

    if mr == 3 then
        game.StarterGui:SetCore("ChatMakeSystemMessage", {
            Text = deadPlayer.. " found a Creeper!";
            Font = Enum.Font.Highway;
            Color = red.Color;
            FontSize = Enum.FontSize.Size96;
        })
    end
end)

Also, my main is "LukeMasterVader", if you're curious. Haven't used this site in years, so I forgot my password, and I don't even know what email I signed up with.

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

I would use a main script that tracks the death of each player and use FireAllClients to notify players.

Script

local Players = game:GetService("Players")
local PlayerDiedChatEvent = game:GetService('ReplicatedStorage'):WaitForChild('PlayerDiedChatEvent')

local function PlayerJoined(Player) 
    Player.CharacterAdded:Connect(function(character)
        local Humanoid = character:WaitForChild("Humanoid")
        if Humanoid then 
            Humanoid.Died:Connect(function()
                PlayerDiedChatEvent:FireAllClients(Player)
            end)
        end
    end)
end

Players.PlayerAdded:Connect(function(Player)
    PlayerJoined( Player )
end)

for _, Player in pairs(Players:GetPlayers()) do 
    PlayerJoined(Player)
end

LocalScript

local PlayerDiedChatEvent = game:GetService('ReplicatedStorage'):WaitForChild('PlayerDiedChatEvent')

PlayerDiedChatEvent.OnClientEvent:Connect(function(PlayerWhoDied)
    print (PlayerWhoDied, 'just kicked the can')
end)
Ad

Answer this question