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

Help to CharacterRemoving. Doesnt work?

Asked by 4 years ago
local Players = game:GetService("Players")
local plr = game.Players.LocalPlayer
local frames = script.Parent


local function onCharacterDespawned(player)
    frames.PlayerName = player.Name .. " Has been killed"
            print("Working 2!")

end


local function whenYouDie(player)

    plr.CharacterRemoving:connect(function()
        onCharacterDespawned(player)
        print("Working!")

    end)
end

Been trying random things for 2hrs, nothing works.

Its inside the starterGUI folder in a local script, inside of the frame itself.

I want the textLabel to call out the name, of the person who just died.

Thanks in advance.

3 answers

Log in to vote
0
Answered by
Elixcore 1337 Moderation Voter
4 years ago

You never call the function in the script, for a function to run you must call it after defining it.

All you do is defining without calling them.

Proper example of a function:

local function sayHello()
    print("Hello")
end --defining it

sayHello() -- calling it

--> Output: 'Hello'
Ad
Log in to vote
0
Answered by
srimmbow 241 Moderation Voter
4 years ago
game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        local humanoid = char:WaitForChild("Humanoid")
        if humanoid then
            humanoid.Died:Connect(function()
                print(plr.Name.." has died") --Here put the gui stuff
            end)
        end
    end)
end)
0
Hmm it doesn't work. it is because its a localscript? If i have to put it in a regualr script, how do i accses the text value in the GUI since the script is in another folder then Animine 0 — 4y
0
yes put it in a script. You have to use a remote event and use the FireAllClients function which makes everyone's gui say they have died. go to roblox developer hub and search fireallclients to see how it works srimmbow 241 — 4y
Log in to vote
0
Answered by 4 years ago

Lol this made it work aswell. But would be much cooler, if i could make it work in the localscript...

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterRemoving:Connect(function(character)
        print(player.Name .. " died due to ????")
    script.Parent.Parent.StarterGui.LastKilled.Frame.PlayerName.Text = player.Name .. " Just died!"



    end)
end)

Answer this question