This script has it so that when you click a button, a part from serverstorage clones itself and should move the clone to the players inventory/backpack. But to doesn't.
local button = workspace.mailorjobpart.ClickDetector local door = workspace.Door local greenpart = door.SelectionBox local letter = game.ReplicatedStorage.letter local letterclone = letter:Clone() button.MouseClick:Connect(function(onclicked) letterclone.Parent = game.Players.LocalPlayer:FindFirstChild("Backpack") end)
Use replicated storage, why?
Replicated Storage
Local scripts and scripts can access it
Server Storage
Only server scripts can access it, use this for storing maps etc
Also i suggest using a server script to move it into the players backpack, otherwise it may cause glitches and won't show up for everyone. Use a remote event so that you can still press the button.
You are using a LocalScript
, which can cause problems.
Remember: Anything done in a LocalScript
will only show on the client side. In order to make the letter appear for everyone, you should clone the object and move it to the player's backpack in a ServerScript
. You can use RemoteEvent
s for this (look those up if you don't know what those are).
The whole operation can infact be done from the server side, as a clickdetecter being clicked ( as shown as the initiation of the giving in the initial script above ), can infact be detected by a server-side script.
From your script, I can see you have used LocalPlayer, which is part of a local script. A local script is not the correct type of script you should be using in this context, and I'll explain why. A local script's effect is purely seen on the side of the client it's executed inside of. This means that neither the server nor any other player knows of what happens in this script, meaning in this case, only the player that clicked the clickdetector would "know" of the cloned tool. A server-script, however, is automatically broadcasted to all clients, and therefore is able to achieve the effect I believe you are trying to achieve.
Here is the script I used in my test:
tool = script.TestTool clickdetector = workspace.TestPart.ClickDetector clickdetector.MouseClick:Connect(function(plr) local clone = tool:Clone() clone.Parent = plr.Backpack end)
Put this in ServerScriptService, and place your tool inside of the script.To adapt, just change the routes of the variable tool, and the clickdetector.
Hope this helped.