In short, I have some clearance tools, but they also have game passes so if you have a gamepass it would give you one of them. But some teams also have those cards. So it may be that you buy a clearance 2 card but your team has a clear 3 I tried making a script that will make it so they would only have the highest card in their inventory and the rest would be deleted so for example if they have a clearance 1 and a clearance 3 the clearance 1 would be removed as it’s pretty useless if you have a higher ranking one.
So, I made this script but it did not seem to work.
local character = player.Character
-- Find the tools in the player's inventory
local clear1 = player.Backpack:FindFirstChild("Clear1")
local clear2 = player.Backpack:FindFirstChild("Clear2")
player.CharacterAdded:Connect(function()
if clear1 and clear2 then
-- Remove Clear1 from the player's inventory
clear1:Destroy()
end
end)
Move the two lines that check for the cards to inside the event function.
local character = player.Character
player.CharacterAdded:Connect(function()
-- Find the tools in the player's inventory
local clear1 = player.Backpack:FindFirstChild("Clear1")
local clear2 = player.Backpack:FindFirstChild("Clear2")
if clear1 and clear2 then
-- Remove Clear1 from the player's inventory
clear1:Destroy()
end
end)
Local or client activity is not replicated to server unless its physics related. This is due to FE, the work around to this would be to use remote events or functions to communicate from client-server. However, with this exploitation is possible so its important to add checks to verify that the data being passed is correct.
I just tried this using a server script in the workspace and it worked:
game:GetService("Players").PlayerAdded:Connect(function(player)
--Set up this event for every player that joins
player.CharacterAdded:Connect(function(character)
--Run each time character spawns
local sprinttool = player.Backpack:FindFirstChild("Sprint")
if sprinttool ~= nil then
print("No sprinting for you")
sprinttool:Remove()
end
end)
end)
But what if there are two of the same tool with the same name, how would it notice it and remove one of them? or just remove them until there is only one of them.