How to make an infinite key tool?

Hello guys,

So I got a key here that equips whenever you click it on it but as obviously expected, it disappears from its spot afterwards. I want it to function though like how the horror game “The Mimic” has its keys to were they’re like anchored on the floor (I think?) and everyone can pick them up infinite times as long as you don’t already have one on you. This is to prevent players that would’ve found the key first to leave making the key be gone forever or incase you die, it doesn’t permanently disappear from your inventory and you can pick it up again with no problem.

image

image

1 Like

You can just clone the tool before parenting it to whoever clicked It first.

1 Like

How would that look like and under what line should I implement it in? Sorry, I don’t have much experience with scripting like that.

1 Like

Add this line of code in your click function, before the line of parenting the tool.

local clone = tool:Clone()
clone.Parent = workspace
clone.Handle.CFrame = script.Parent.CFrame

Like this? It clones the key only once and I’m not able to click to pick it up anymore. The only way it lets me is to manually touch it but even then, it equips more than 1 of the same key. Tell me if I’m doing something wrong.

image

1 Like

You are still changing the tool parent instead of the clone parent.

1 Like

What do you mean? I’m confused a bit right now.

What do you mean by that? How is that possible? Can you record the incident?

Like I can’t pick it up by clicking on it now, only touching it. Yeah I’ll record 1 sec.

1 Like

Replace tool.Parent = workspace with

clone.Parent = workspace[player]

Also use ``` to format code instead of screen shotting.

Edit: oh didn’t see that, like @ItzMeZeus_IGotHacked said put it inside the players backpack, player.Backpack I believe.

1 Like

But that still wouldn’t work because we are cloning it and then just put it into the character again.

I fixed it a little bit right now. I can pick it up again by clicking on it and it clones properly but this time it’s still letting me collect more than one when already having a previous one equipped and am also able to pick the tool up by stepping on it as a secondary way to equip it which is also what I don’t want.

Add a debounce in the script to prevent getting more than 1 tool. About stepping on it, I’m not sure.

1 Like

Would I put the debounce under the “tool.Parent = game.Workspace[player.Name]” line? What would the debounce look like in this situation for the script? Sorry for the inconvenience, I just want it to work properly.

That’s because you didn’t add a script that detect tool inside a player

try this:

local Key = script.Parent.Parent

local function click(player)

local tool = player.Backpack:FindFirstChild(Key) or player.Character:FindFirstChild(Key) 
if tool then

local clone = Key :Clone()
clone.Parent = workspace
workspace[player.Name].Humanoid:EquipTool(clone)
end

end

script.Parent.ClickDetector.MouseClick:Connect(click)

Aight, I’m not on studio soo the format is a bit weird.

let me know if it doesn’t work

1 Like

I add this script as a new seperate one under Handle correct? If so, I tried it and it didn’t really seem to fix it.

image

Hasn’t really changed much.

Would making it a localscript and giving the item through removevent work?

I wouldn’t know how to as I don’t specialize in scripting.

Yep, should be something like this but there is a small bool error so I have edited it with lots of comments to help explain to @EchoWinds.

BTW @EchoWinds this is the new clone tool script, should only be one script in order to avoid multiple mouse click events.

--gets the key
local Key = script.Parent.Parent

local function click(player)
    --Finds the key inside players backpack or players character via the name of the tool
	local isKeyAlreadyGiven = player.Backpack:FindFirstChild(Key.Name) or player.Character:FindFirstChild(Key.Name)
    --If the tool isn't given
	if not isKeyAlreadyGiven then
--then
		local clone = Key:Clone()--copies the key
        --puts it in the players backpack
		clone.Parent = player.Backpack
	end
end

script.Parent.ClickDetector.MouseClick:Connect(click)
1 Like

Thank you so much omg!! Been trying to make this work for the past hour and half or so :smiley: I got another quick question that’s still regards the key. How can I keep the key in 1 spot without it getting flung whenever you step on it acting as if anchored? Like you know how if you anchor a tool it won’t work? What I’m looking to do is so it acts as if it’s anchored on the floor but in reality isn’t and can still pick it up normally. Once again, The Mimic’s keys would be a great example of what I mean.

Like this