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

Please Help I really need it Need away so if that person goes offline?

I tried doing it like taking there name and seeing but nope I want it so that when they go offline out of the game it resets the text to Become Owner and I want to also add When they leave it resets the the door back to transparent to 0 and cancollide to true after

while true do
function onTouch(hit)
    local name = hit.Parent.Name
    local player = hit.Parent
    local plr = hit.Parent:FindFirstChild("Humanoid")
     if plr then
    local check1 = game.Players:GetPlayerFromCharacter(hit.Parent)
      if check1 then
        local check2 = check1:WaitForChild("leaderstats")
          if check2 then
            local check3 = check2:WaitForChild("Owner")
              if check3.Value == false then
                  check3.Value = true
                  script.Parent.CanCollide = false
                  script.Parent.Transparency = 1
                print(hit.Parent)
                local model = script.Parent.Parent
                model.Name = name.." Owns This Tycoon"
                local green = game.Teams.GreenTeam
                check1.TeamColor = BrickColor.new("Lime green")
                local h = player:FindFirstChild("Humanoid")
                if h then
	            h.Health = 0
	            plr:WaitForChild("Humanoid")
	            plr.Position = script.Parent
	            if name then
		            print("Good")
	              else model.Name = "Become Owner"
	                     end
                     end        
                end
            end
        end
    end
end
script.Parent.Touched:connect(onTouch)
wait(1)
end


1 answer

✓ Accepted answer

You could register a function to the "PlayerRemoving" event of the game.Players service.

local function onPlayerRemoving(player)
	-- The 'player' argument will be set to the leaving player's
	-- Player instance (E.g:  If I left the game, then player would
	-- refer to game.Players.Link150).
	
	print(player.Name .. " left the game!")
end


-- We pass the name of our function to "connect()". This is called a
-- *callback*. Basically, our function will be *called back* whenever
-- the PlayerRemoving event is fired.
game.Players.PlayerRemoving():connect(onPlayerRemoving)

Hope this helps. If it does, please make sure to upvote and check my answer as accepted. If you need anything else, feel free to ask.

3 comments

0

Ok so just wait I get this now but I don't get where to put it can you help me and ill for sure give you a upvote

0

Alright. Whatever you do, make sure to always place the "onPlayerRemoving()" function above the event connection, the last line of the code. Otherwise Lua will complain it cannot find it. Other than than, you're pretty much free to put this code anywhere in your script. Most people place their functions at the very top of their script, preceded only by global scope variable declarations.

0

As for the event registration line, most people usually place it at the very end of the code. The rule here is that the "onPlayerRemoving()" function will not be called until this line is executed.

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