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)
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)
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.