So I have a pet system but pets are button. So I made a sell button but when you press it it deletes all the button with the same name out of the player the remote event is sent from the local script to the server. In the sellTable are the names of buttons that need to be sold out of the player inventory, lets say there 3 green buttons and I hit sell on one of them it sell them all. The script will go thuogh the inventory if it finds a name that is in the table it should sell it and delete it from the table, please help.
serverscript
local sellButton = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("SellButtonRemoteEvent")
sellButton.OnServerEvent:Connect(function(player, sellPrice, sellTable)
player.leaderstats.Money.Value += sellPrice
local amountButton = #sellTable
for i,v in pairs(player.ButtonInventory:GetChildren()) do
if table.find(sellTable,v) then
local index = table.find(sellTable, v.Name)
table.remove(sellTable, index)
v:Destroy()
end
end
end)
I believe the problem lies in this line,
this line is trying to find the same Button Instance instead of the Name,
to find the name of the button, you should use:
if table.find(sellTable, v.Name) then
Also, you can move the index variable above the if statement as the variable stores the index number value
Here is the full script:
local sellButton = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("SellButtonRemoteEvent")
sellButton.OnServerEvent:Connect(function(player, sellPrice, sellTable)
player.leaderstats.Money.Value += sellPrice
local amountButton = #sellTable
for i,v in pairs(player.ButtonInventory:GetChildren()) do
local index = table.find(sellTable, v.Name)
if index then
table.remove(sellTable, index)
v:Destroy()
end
end
end)
oh god nonono do not ever trust the client with such values
always check if its even a table because exploiters might send something else than a table
another thing I found a very big vulnerability in your script
exploiter could do something like this in order to get infinite money!
local sellButton = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("SellButtonRemoteEvent")
sellButton:FireServer(9999999999999999999999)
please add some sanity checks or just check for those items on serverside rather than clientside!!
local sellButton = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("SellButtonRemoteEvent")
sellButton.OnServerEvent:Connect(function(player, sellPrice, sellTable)
if typeof(sellTable) ~= "table" then
return
end
player.leaderstats.Money.Value += sellPrice
local amountButton = #sellTable
for i,v in pairs(player.ButtonInventory:GetChildren()) do
local index = table.find(sellTable, v.Name)
if index then
table.remove(sellTable, index)
v:Destroy()
end
end
end)
this doesnt patch this fully because the exploiter could still pull out the same thing
local sellButton = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents"):WaitForChild("SellButtonRemoteEvent")
sellButton:FireServer(9999999999999999999999,{})
and you got infinite money :((
if you dont know who is “exploiter” basicially its a person that uses UWP version of roblox in order to “bypass hyperion” and then he injects his executor and he can run custom code like the one above in order to get infinite money in your game