what do i add to this script to make the text update when the “owner leaves”.
Example: the player that touched the spawn part their username will be the text on the part but when that one player leaves then the text will go back to normal.
The text: "owner: " when player touches the spawn part the text for example will be: “owner: Yo2uber99” but when that player leaves the game the it goes back to the original text: "owner: "
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local name = player.Name
local text = script.Parent.Parent.playername.SurfaceGui.TextLabel
text.Text = "owner: "..name
end)
game.Players.PlayerAdded:Connect(function(player)
if player.UserId==1 then --replace 1 with your userid
local text = script.Parent.Parent.playername.SurfaceGui.TextLabel.Text="text here"
text.Text = "owner: "..name
end
end)
game.Players.PlayerRemoving:Connect(function(player)
if player.UserId==1 then --do the same thing above (change the 1 to your userid)
--do stuff here
end
end)
if you’d like to learn more of what you could do, you can visit this website: Players (roblox.com)
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local name = player.Name
local text = script.Parent.Parent.playername.SurfaceGui.TextLabel
text.Text = "owner: "..name
game.Players.PlayerRemoving:Connect(function(plr)
if plr == player then
text.Text = "owner: "
end
end)
end)
he’s not talking about the owner of the game or specific players. He’s talking about anyone who touches a part. Basically, they’d be the owner of the part or something like that.