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

player removing script with nil value?

game.Players.PlayerRemoving:Connect(function(plr)
	nm = game.Players:GetPlayerFromCharacter(plr.Parent)
	game.StarterGui.teleport.sword.Text = nm.Name
	
	
end)

i want to show people on gui who leaves the server but its not working

2 comments

0

you're using startergui instead of playergui. Also, is this a local script or a server script?

0

server script... if i put it into the gui it will wotk? and make it local script?

1 answer

✓ Accepted answer

New answer: The reason why it was NOT working was because I forgot that remote events existed. My bad lol

SERVER SCRIPT

local Players = game:GetService("Players")
local PlayerLeft = game:GetService("ReplicatedStorage").PlayerLeft

function onPlayerRemoved(Player)
	PlayerLeft:FireAllClients(Player)
end

Players.PlayerRemoving:Connect(OnPlayerRemoved)

CLIENT SCRIPT

local Text = script.Parent
local PlayerLeft = game;GetService("ReplicatedStorage").PlayerLeft

function  onPlayerLeftFired(Player)
	Text.Text = Player.Name.." left the game!"
	wait(3)
	Text.Text = ""
end

PlayerLeft.OnClientEvent:Connect(onPlayerLeftFired)

In the setup above we're going to need to have a remote event in ReplicatedStorage called "PlayerLeft". We'll then make the server script in the code above be in ServerScriptService. We'll have the client script in the textlabel you've created (assuming you've made one). That's all!

7 comments

0

That also won't work, GUIs are cloned into the PlayerGui locally, essentially making them inaccessible to the server

0

not working

0

local Players = game:GetService("Players") function onPlayerRemoving(plr) local nm = Players:GetPlayerFromCharacter(plr.Parent) for i,v in pairs(Players:GetPlayers()) do v.PlayerGui.teleport.sword.Text = nm.Name wait(3) v.PlayerGui.teleport.sword.Text = "" end end) Players.PlayerRemoving:Connect(onPlayerRemoving) i wrote this in server script service but...

0

tnt why not make a remote event

0

ok I remade it

0

you do know that PlayerRemoving works on the client side, right?

0

yeah but im too lazy to change my answer again

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