You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I’m trying to make a Give Tray GUI
What is the issue?
When I click on what tray I want it does this that on the video
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried adding :Destroy instead of :Remove in it still doesn’t work Right
-- local tool = game.Workspace:WaitForChild("CupcakeTray")
local player = game.Players.LocalPlayer
local cookie = script.Parent
cookie.MouseButton1Click:Connect(function()
if player.Character then
for _, item in pairs(player.Character:GetChildren()) do
if item.Name == tool.Name then
item:Destroy()
end
end
end
if player.Backpack then
for _, item in pairs(player.Backpack:GetChildren()) do
if item.Name == tool.Name then
item:Destroy()
end
end
end
local clonedTool = tool:Clone()
clonedTool.Parent = player.Backpack
end)
Alr, You would need to use a remote event.
Create a remote event to Replicated Storage rename it to HandleCupcakeTray
Here is the local script
local tool = game.Workspace:WaitForChild("CupcakeTray")
local player = game.Players.LocalPlayer
local cookie = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local handleCupcakeTrayEvent = ReplicatedStorage:WaitForChild("HandleCupcakeTray")
cookie.MouseButton1Click:Connect(function()
-- Fire the RemoteEvent to the server
handleCupcakeTrayEvent:FireServer()
end)
This is a server script place in serverscriptservice
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local handleCupcakeTrayEvent = ReplicatedStorage:WaitForChild("HandleCupcakeTray")
handleCupcakeTrayEvent.OnServerEvent:Connect(function(player)
local tool = game.Workspace:WaitForChild("CupcakeTray")
-- Check and destroy existing tools in the character
if player.Character then
for _, item in pairs(player.Character:GetChildren()) do
if item.Name == tool.Name then
item:Destroy()
end
end
end
-- Check and destroy existing tools in the backpack
if player.Backpack then
for _, item in pairs(player.Backpack:GetChildren()) do
if item.Name == tool.Name then
item:Destroy()
end
end
end
-- Clone the tool and add it to the player's backpack
local clonedTool = tool:Clone()
clonedTool.Parent = player.Backpack
end)
You may need to edit this to work with your system.