Sword won't clone after being picked up

Hi, this is my first post on Devforum so sorry for any mistakes in the text!

Ok, now to my issue. I’m working on a simple fightning game where all the players fight with swords. I’m pretty new to scripting so I’m making the game simple. The game works so that when you load or spawn into the game there is a table infront of you with a sword so when you click the sword it gets placed in your inventory. That the sword goes into your backpack works well, but my issue is that I want it to clone when it’s picked up by a player so that others can pick it up. I have tried a few ways that I found on the internet but it still doesn’t work. If anyone here has a solution, please reply to me. Thank you!

Here is my script:

-- The script is in the handle of the sword
--To make the Sword clickable so you can pick it up

local tool = script.Parent.Parent
local clickdetector = script.Parent.ClickDetector


local function pickup(player)
	tool.Parent = game.Workspace[player.Name]
	
	while true do --To make it so that the sword clones on the table so that other players can pick it up
		wait(.5)
		if tool.Parent == not game.Workspace then 
			tool:Clone().Parent = workspace
		end
	end
	
end

clickdetector.MouseClick:Connect(pickup)

local touchinterest = script.Parent:FindFirstChild("TouchInterest")

touchinterest:Destroy()


-- This is to make sure that you can only collect the Sword by clicking it, not touching it

This is my first post on DevForum so sorry for any mistakes in the text🙃

2 Likes
local Tool = script.Parent.Parent
local ClickDetector = script.Parent.ClickDetector

ClickDetector.MouseClick:Connect(function(Player)
	Tool:Clone().Parent = Player.Character --// If you want the tool to clone into the players Backpack just change "Player.Character" to "Player.Backpack"
end)

script.Parent.CanTouch = false --// Instead of deleting the TouchInterest just set the CanTouch property to false
3 Likes

Thank you so much, I was so frustrated but now it works exactly as I want! Thank you man :smiley:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.