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

player removing script with nil value?

Asked by 4 years ago
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

0
you're using startergui instead of playergui. Also, is this a local script or a server script? theking48989987 2147 — 4y
0
server script... if i put it into the gui it will wotk? and make it local script? tnt54868726 3 — 4y

1 answer

Log in to vote
1
Answered by
Mr_Unlucky 1085 Moderation Voter
4 years ago
Edited 4 years ago

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!

0
That also won't work, GUIs are cloned into the PlayerGui locally, essentially making them inaccessible to the server theking48989987 2147 — 4y
0
not working tnt54868726 3 — 4y
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... tnt54868726 3 — 4y
0
tnt why not make a remote event Mr_Unlucky 1085 — 4y
View all comments (3 more)
0
ok I remade it Mr_Unlucky 1085 — 4y
0
you do know that PlayerRemoving works on the client side, right? theking48989987 2147 — 4y
0
yeah but im too lazy to change my answer again Mr_Unlucky 1085 — 4y
Ad

Answer this question