✓ Accepted answer
Like someone said before, you will need to abide to the FilteringEnabled rules. Previously, your code would look perfectly fine but not anymore.
In order to get a tool that everyone can see, you need to use a Remote Event to establish a connection with the server.
You keep all client sided scripting in your GUI's script, so pretty much only connecting to the click. Afterwards, you want to fire the server, which will give you the tool.
I will give you a fairly simple example, which you might want to improve, in order to prevent exploiters to get the cart in their inventory.
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage:WaitForChild("CartEvent")
script.Parent.MouseButton1Click:Connect(function()
event:FireServer()
end)
Now in the server's script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = Instance.new("RemoteEvent")
event.Name = "CartEvent")
event.Parent = replicatedStorage
local tool = script.Parent.Cart
event.OnServerEvent:Connect(function(player)
tool:Clone().Parent = player.Backpack
end)
Like I mentioned before, you might want to improve this code by adding checks that prevent non-staff members to get the tool. You can do this by checking their rank in your group, and only give them the tool if they are indeed in a staff position.
Useful documentation: Remote Event, ReplicatedStorage, GetRankInGroup()
2 comments
you should probably abide by filtering enabled rules
How? sorry to be that guy