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

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

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)

1 comment

0

Tip: Wait(0) is not possible. Make it simply wait()

2 answers

✓ Accepted answer

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)

2 comments

0

Didn't even see that he didn't put a colon. Nice work!

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.

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.

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