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

Repeat until player teamcolor is ghost grey?

Asked by
sebanuevo 123
3 years ago
Edited 3 years ago

Hello,im making a script that gives you a tool if you own a gamepass The thing is that in my game you change teams, and i need to check if the player is on that team to give him the tool, which works very well but, if you hold the tool the loop will act and set the parent to the player backpack, which makes impossible to hold the tool.

So how do i make this loop wait until the player is on that team and not loop parent backpack the tool?

Line of my code im referring to:

    if haspass == true then
        while wait() do
            if player.TeamColor == BrickColor.new("Ghost grey") then
                player.Parent = player.Backpack
            end
        end
    end
end)

My full code:

local mps = game:GetService("MarketplaceService")
local replicatedstorage = game:GetService("ReplicatedStorage")
local tool = replicatedstorage:WaitForChild("MartilloDorado")
local gamepassid =  11019773

game.Players.PlayerAdded:Connect(function(player)
    wait(1)
    local haspass = false
    local success,message = pcall(function()
        haspass = mps:UserOwnsGamePassAsync(player.UserId, gamepassid)
    end)

    if haspass == true then
        while wait() do
            if player.TeamColor == BrickColor.new("Ghost grey") then
                player.Parent = player.Backpack
            end
        end
    end
end)

1 answer

Log in to vote
0
Answered by
sebanuevo 123
3 years ago

I already solved thanks to the man that helped

Fixed Script:

local mps = game:GetService("MarketplaceService")
local replicatedstorage = game:GetService("ReplicatedStorage")
local tool = replicatedstorage:WaitForChild("MartilloDorado")
local gamepassid =  11019773

game.Players.PlayerAdded:Connect(function(player)
    wait(1)
    local haspass = false
    local success,message = pcall(function()
        haspass = mps:UserOwnsGamePassAsync(player.UserId, gamepassid)
    end)
while wait(1) do
    repeat wait (1) 
    until haspass == true and player.TeamColor == BrickColor.new("Ghost grey")  
    if player.Backpack:FindFirstChild("MartilloDorado") == nil and player.Character:FindFirstChild("MartilloDorado") == nil then
            tool:Clone().Parent = player.Backpack
            player.Backpack:FindFirstChild("Martillo"):Destroy()
        end
    end
end)

Ad

Answer this question