Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Cloning a tool refuses to let it work?

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function(click)
	if player.leaderstats.Cash.Value >= 10 then
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 150
		
		game.ReplicatedStorage.Tools.ClassicTimebomb:Clone().Parent = player:WaitForChild("Backpack")
	end
end)

When the tool is cloned into the backpack, it seems that I am able to hold it, however it doesn't respond when I click it. I've tried this with a rocket launcher too. It doesn't seem to work, and I'm stumped. Any ideas why?

2 comments

0

Did you try printing on each line to see where your code runs up to.

0

Yes, the code goes all the way through. I have the weapon in my backpack, and I can equip it, however, when I try to click to use the weapon it refuses to work.

1 answer

You are cloning it client-side, meaning that it will only be seen by the client and that's why it's not working most likely. Instead of doing it in the local script, you should send a remote containing tool name that the server will handle and clone the tool. Something like this:

Client code (in the localscript):

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remote = ReplicatedStorage:WaitForChild("Remote") -- You should put name and path to RemoteEvent here
local player = game.Players.LocalPlayer
local Debounce = true

script.Parent.MouseButton1Click:Connect(function(click)
	if Debounce then
		Debounce = not Debounce
		Remote:FireServer("ClassicTimebomb")
		wait(.5)
		Debounce = not Debounce
	end
end)

Server code (Script inside ServerScriptService):

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remote = ReplicatedStorage:WaitForChild("Remote") -- You should put name and path to RemoteEvent here

Remote.OnServerEevent:Connect(function(Player,Item)
	if Item == "ClassicTimebomb" then
		local Price = 150
		local Cash = Player:FindFirstChild("leaderstats").Cash
		if Cash then
			if Cash.Value >= Price then
				Cash.Value = Cash.Value - Price
				ReplicatedStorage.Tools:FindFirsChild(Item):Clone().Parent = Player:WaitForChild("Backpack")
			end 
		end
	end
end)

Note: I didn't test it so if there are any problems or questions feel free to comment.

This discussion is preserved as it was. New answers, comments, and votes are closed.