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

Why does this not work?

Asked by 8 years ago

Theres no output I'm trying to get the player removing to work this is a tycoon I want it so if that player leaves it resets the tycoon Ive asked this several times I need help

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
                game.Players.PlayerRemoving:connect(function(player)
                           if player == false then
                                    check3.Value = false
                                    model.Name = "Become Owner"
                                     script.Parent.CanCollide = false
                                      script.Parent.Transparency = 1
                               end
                          end)
                     end        
                end
            end
        end
    end
end
script.Parent.Touched:connect(onTouch)

2 answers

Log in to vote
0
Answered by
Link150 1355 Badge of Merit Moderation Voter
8 years ago

First of all your Tycoon script has a major design flaw. Instead of having a string Value (an Object that holds a text value) inside of the tycoon model to keep track of the name of the player who owns the tycoon you instead keep a boolean Value (an Object that holds a true or false value) on the player, which tracks whether a player owns ANY tycoon or none at all.

This means whenever a player touches the brick, it sets their own boolean value to true and changes the name of the tycoon's model to "<PlayerName> Owns this Tycoon". But the game never keeps track of who owns it, only that they own one, so anyone who touches the brick will now see their name displayed above it, even if a player has previously claimed this tycoon.

This being said, let's now take a look at the true subject of your question.

The code inside the PlayerRemoving callback is never being executed because the if player == false then statement always fail. PlayerRemoving always pass the player's game.Playersinstance as first argument so you can know who left the game.

So let's say I were to leave the game, your callback -- The function you connect()'ed to the PlayerRemoving event -- would be given the object game.Players.Link150. But here you are testing whether "player" is false, which isn't: It is equal to game.Players.Link150.

Hope that helped you. Be sure to upvote and accept my answer if it did. If you need anything else, leave me a message.

0
I should just quit making my game if I added you oin team create could you help me out that way like its ok if you don't want to ill make sure I add you as a scripting helper I really want to make this then you can see everything johndeer2233 439 — 8y
0
Sure. I'd be glad to help. I've never used Team Create before, though. Link150 1355 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
game.Players.PlayerRemoving:connect(function(player)
        local PlayerThatLeft = player.Name

        local Area = game.workspace:GetChildren()

    for i, v in ipairs(Area) do
        if v.Name = PlayerThatLeft then
            v. -- Do whatever to reset the tycoon
        end
    end 


end

end)

On Line 7 what it does is look at everything in the workspace to find something with the same name as the player who is leaving, If your tycoon changes the name of something to the player who is using it it will find that, then you do whatever

For example lets say that a part with the player name is in the tycoon and you want to edit another parts color when they leave We'll name that part 'Dookie'(lel)

so you would change line 8 to

v.Parent.Dookie.BrickColor = BrickColor.new('Whatever')

I saw in your script you wanted to access the player

game.Players.PlayerRemoving:connect(function(player)
Leaderstats = player:WaitForChild('leaderstats')
Owner = Leaderstats:WaitForChild('Owner')


end)

Hope this has helped

0
You know you could simply retrieve the player's character through player.Character, right? Plus this would be much more reliable and efficient than to loop through all of game.Workspace's children... Link150 1355 — 8y
0
^ TheTermaninator 45 — 8y

Answer this question