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

Message made more than once?

Asked by 8 years ago
function onTouch(hit)
    local name = hit.Parent.Name
    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 == true then
                local m = Instance.new("Hint",game.Workspace)
                m.Text = name.." Already Owns A Tycoon"
                wait(4)
                m:Destroy()
                wait(.5)
            end
              if check3 then
                  check3.Value = true
                  script.Parent.CanCollide = false
                  script.Parent.Transparency = 1
                print(hit.Parent)
                end
            end
        end
    end
end
script.Parent.Touched:connect(onTouch)
wait(1)

I need it to only make 1 message not 8-9?

1 answer

Log in to vote
0
Answered by 8 years ago

You could just add a simple check to see if the hint already exists in workspace.

Here is your revised script:

function onTouch(hit)
    local name = hit.Parent.Name
    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 == true then
                local m 
                if game.Workspace:FindFirstChild'Hint' then
                    print'Hint exists!'
                else
                    m = Instance.new("Hint",game.Workspace)
                end
                m.Text = name.." Already Owns A Tycoon"
                wait(4)
                m:Destroy()
                wait(.5)
            end
              if check3 then
                  check3.Value = true
                  script.Parent.CanCollide = false
                  script.Parent.Transparency = 1
                print(hit.Parent)
                end
            end
        end
    end
end
script.Parent.Touched:connect(onTouch)
wait(1)
Ad

Answer this question