Tool dissapiers when another player clicks it

Hi there!

I sadly am completely new to scripting, but I’m trying to learn. I made a small simple quest where, if a player finds the ‘hidden camera’, they get to keep it in their backpack as a present.


So far, I’ve managed to make it able for players to click the camera and equip it in their backpack. The only problems I’ve been having that I can’t seem to figure out (or find a post about it on the forum),
is that when another player clicks the camera, it disappears from the backpack from the first player. It seems like only one player is able to equip the camera in the whole sever I was thinking about duplicating the camera tool in ServerStorage to the same amount of the max server player size, but I believe that wouldn’t really resolve the problem.

This is the script I’m using for equipping the camera tool:

local tool = game.ServerStorage["Matt's Camera"] local klone = tool:clone() script.Parent.ClickDetector.MouseClick:connect (function(plr) if klone.Parent ~= plr.Backpack then klone.Parent = plr.Backpack else end end)

I would really appreciate a helping hand!

You cloning outside the function try cloning inside of it

How exactly would I do that? I wrote this script using a little guide and tutorial. I’m sadly not very familiar with it!

Try this:

local tool = game.ServerStorage["Matt's Camera"]

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
    if not plr.Backpack:FindFirstChild("Matt's Camera") and not plr.Character:FindFirstChild("Matt's Camera") then
        local clonedTool = tool:Clone()
        clonedTool.Parent = plr.Backpack
    end
end)

This will check if the player has the tool in either his backpack or character. Tools that are unequipped are stored in the backpack while tools that are equipped are stored in the the character. Then we clone the tool and parent it to the player’s backpack.

1 Like

Make sure your camera in workspace is a model rather than a tool.

Now type this script

script.Parent.ClickDetector.MouseClick:Connect(function(player)
    local Tool = game.ServerStorage.Camera:Clone() -- change this to your item's name
    Tool.Parent = player.Backpack or player.Character -- making the Camera's parent to the player's character or Backpack.
    script.Parent:Destroy()
end)

This will give the camera to the player every time they click on it, which is not ideal in this case.

Sorry I forgot to destroy the part in the workspace.
I have edited the script.
Sorry :sweat_smile:

Yeah, but when you destroy the part, it will destroy for everyone, making it impossible for anyone else to get the camera. A better way of doing this is checking if the tool exists in either the backpack or the character, then if it doesn’t, clone it and parent it to the player’s backpack. (see my post above)

I’m gonna give it to try! I’ll have to wait for someone to test it with me at the same time to see if it works, but I have high hopes!

I am available to test, so if you need me, you can always mention me or you can just run a test server of 2 players.

Try using this instead

local tool = game.ServerStorage["Matt's Camera"]

-- To
local tool = game.ReplicatedStorage["Matt's Camera"]

Make sure your tool is in Replicated Storage not Server Storage

Maybe that’ll fix the issue if it doesn’t you can try sending me a copy of the tool for me to test if you want to or something

That’s the same script Deemsx sent.

Oh ok, nvm then

But she can try to put it in replicated storage tho

local tool = game.ServerStorage["Matt's Camera"]
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
local klone = tool:Clone() 
if plr.Backpack:FindFirstChild("Matt's Camera") == nil then
klone.Parent = plr.Backpack
end
end)

Simply move the klone local inside of the function
and change if klone.Parent ~= plr.Backpack then to if plr.Backpack:FindFirstChild("Matt's Camera") == nil then

I tried, but it only works when it is put in ServerStorage.

1 Like

If you’d have some free time right now, that would be awesome!

It works for me tho? You maybe haven’t put stuff in the correct order,

The Part u click is in workspace and in it theres a click detector and script

and the tool (with the handle) place it in replicated, if it still doesn’t work then sorry…

It doesn’t matter whether the Tool is in ServerStorage or ReplicatedStorage since the code is in a server Script.

1 Like

Wait, what type of script is giving you the tool? Local or ServerSide Script?

I’m not sure what the difference is, sadly - I’m very new to this! I’m mostly just a developer in building.

I believe it is a local script. But, with the code given by BPilot, it now is fixed!