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

How do I remove a tool from the backpack on connect if the player is a certain rank?

Asked by 5 years ago
Edited 5 years ago

I want to remove a tool from a player who is a certain rank in a group but only when they connect, how do I do it?

This is what I've tried so far:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    if player:GetRankInGroup(GroupID) == Rank then
        wait(0)
        local suitcase = player.Backpack:FindFirstChild("Suitcase")
        suitcase.Destroy()
    end
end)
0
Tip: Wait(0) is not possible. Make it simply wait() MustangHeart 67 — 5y

2 answers

Log in to vote
0
Answered by
srimmbow 241 Moderation Voter
5 years ago

First of all, inside of the PlayerAdded function, you can add another function inside of it called CharacterAdded. It runs when someone's character loads.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        if player:GetRankInGroup(GroupID) == Rank then
            wait(0)
            local suitcase = player.Backpack:FindFirstChild("Suitcase")
            suitcase.Destroy()
        end
    end)
end)

Next, you don't need a wait function.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        if player:GetRankInGroup(GroupID) == Rank then
            local suitcase = player.Backpack:FindFirstChild("Suitcase")
            suitcase.Destroy()
        end
    end)
end)

Lastly, suitcase.Destroy() will not work, as Destroy is a function so you have to put a ":" instead of a "."

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        if player:GetRankInGroup(GroupID) == Rank then
            local suitcase = player.Backpack:FindFirstChild("Suitcase")
            suitcase:Destroy()
        end
    end)
end)
0
Didn't even see that he didn't put a colon. Nice work! MustangHeart 67 — 5y
0
Thanks, didn't even realise that I forgot the colon. I had it on before, but re-wrote it for this. That wasn't the main cause, but at least you paid attention. HelpAccountAvian 9 — 5y
Ad
Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

You might wanna try doing player:GetPlayerFromCharacter after Players.PlayerAdded:Connect(function(player).

local Players = game:GetService("Players")

local rank = 1 --Set your specified rank here

Players.PlayerAdded:Connect(function(player)
local h = player.Parent:FindFirstChild("Humanoid")
local p = game.Players:GetPlayerFromCharacter(player.Parent)
if p then
    if p:GetRankInGroup(INSERTGROUPIDHERE) > rank then
        local suitcase = player.Backpack:WaitForChild("Suitcase") --I'd use WaitForChild so we can give it some time to show up)
    wait(3)
        suitcase:Destroy()
    end
end
end)

Basically, let the game find the player from the character so it can get details about its rank in the specified group. Also it looks like you copy and pasted this from somewhere else, because some variables are non-existent. Don't do that. Replace INSERTGROUPIDHERE with the group in question and you should be good to go. Let me know if there are any problems/errors.

Answer this question