Hello! I am having an issue with a selection gui. When you select what you want multiple times and click submit, it should give you one item in your inventory, however it gives you many of them.
Basically I have a LocalScript, and in it there is a value gets changed whenever you select a different animal. Then when you finalize your choice, it fires a remote telling the server to give you the item in your inventory, here being the problem as it gives you as many as you clicked.
I have tried making it change a name of an object, but it still gives me multiple for some reason.
Here is some code if you would like to see:
~LocalScript that triggers remote
local folder = game.Players.LocalPlayer:WaitForChild("Animals")
local event = game:GetService("ReplicatedStorage").Events.AnimalConfig.animalpick
local animalchosen = script.Parent.animalchosen
local confirmation = script.Parent.Parent.Parent.Confirmation
local isSelected = false
for i,v in pairs (script.Parent:GetDescendants()) do
if v:IsA("ImageButton") then
--When button clicked
v.MouseButton1Click:Connect(function()
if animalchosen.Name == v.Parent.Parent.Parent.Name then
isSelected = true
elseif animalchosen.Name ~= v.Parent.Parent.Parent.Name then
isSelected = false
animalchosen.Name = v.Parent.Parent.Parent.Name
if animalchosen then
confirmation.Visible = true
confirmation.MouseButton1Click:Connect(function()
local animalchosenNAME = animalchosen.Name
event:FireServer(animalchosenNAME)
script.Parent.Parent.Parent.Enabled = false
end)
end
end
end)
end
end
~ServerScript where remote is fired
game.ReplicatedStorage.Events.AnimalConfig.deleteanimal.OnServerEvent:Connect(function(player, deleting)
--give player half money back from animal
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + deleting.Cost.Value/2
deleting:Destroy()
end)
local Event = game:GetService("ReplicatedStorage").Events.AnimalConfig.animalpick
Event.OnServerEvent:Connect(function(player,v)
print(v)
end)
game.ReplicatedStorage.Events.AnimalConfig.animalpick.OnServerEvent:Connect(function(player, animalchosenNAME)
print(animalchosenNAME)
--Finds which animal it is
local animal = game.ReplicatedStorage.Characters:FindFirstChild(animalchosenNAME)
--Clones animal to player inventory
local newanimal = animal:Clone()
newanimal.Parent = player.Animals
end)
If anyone knows how to fix my issue or any methods around this that would be great. I apologize if this seems confusing. Thank you for reading. :)

1 comment
Include code please.