Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help to CharacterRemoving. Doesnt work?

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

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'
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)

2 comments

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

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

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.