Item script doesnt work when cloning

  1. I need the item to work… yes, the script gives it to me but the item doesnt work
  2. In a simple way, I have a buy button with a localscript, which gives me the item that I select to buy… but the script that it has inside has no effect
  3. I tried to change the script with another similar to a second item “A mystery box” but the same code doesnt work with the first item “pickaxe”

– Localscript by pressing the button to give me the item “Mystery Box” this script works because the item does what it has to do

local player = game.Players.LocalPlayer
local Cash = player.leaderstats:FindFirstChild("Cash")
local sound = script.Parent.Parent.Parent.Parent.CrateEffect
local surprises = script.Parent.Parent.MysteiousCrate:GetChildren()

script.Parent.MouseButton1Click:Connect(function()
	if Cash.Value >= 900 then
		Cash.Value = Cash.Value - 900 
		sound:Play()
		local chosensurprise = surprises[math.random(1,#surprises)]:Clone()
		local backpack = player.Backpack
		chosensurprise.Parent = backpack
	end
end)

– Localscript by pressing the button to give me the item “Pickaxe” as I said before, it gives me the pickaxe, but in the previous case it does not do what it has to do

local player = game.Players.LocalPlayer
local ironframe = script.Parent.Parent.IronFrame
local goldframe = script.Parent.Parent.GoldFrame
local emeraldframe = script.Parent.Parent.EmeraldFrame
local diamondframe = script.Parent.Parent.DiamondFrame
local amethystframe = script.Parent.Parent.AmethystFrame
local moonframe = script.Parent.Parent.MoonFrame
local button = script.Parent
local cash = player.leaderstats:FindFirstChild("Cash")
local sound = game.ReplicatedStorage.Music.Dance

script.Parent.MouseButton1Click:Connect(function()
	if ironframe.Visible and cash.Value >= 2000 then
		local ironpickaxe = game.ReplicatedStorage.Pickaxes["Iron Pickaxe"]:Clone()
		local backpack = player.Backpack
		ironpickaxe.Parent = backpack
		cash.Value = cash.Value - 2000
		sound:Play()

With the pickaxe script, is the same with the others “iron”, “gold”, “emerald, etc”

– Iron Pickaxe after buying it (when I click it doesn’t work)
Image1.PNG
– Default Pickaxe Stone (it works)

The pickaxe script isnt the problem because if i put the iron pickaxe in the StarterPack (that means, i no longer have to buy it since it is in my inventory, like the stone pickaxe) the pickaxe works

Code for all pickaxes (if you think that’s the problem):

local tool = script.Parent
local sound = script.Parent.Handle.Hit

local function mine()
	local str = Instance.new("StringValue")
	str.Name = "toolanim"
	str.Value = "Slash"
	str.Parent = tool
	tool.Mining.Value = true
	wait(0.25)
	sound:Play()
	tool.Mining.Value = false
end

tool.Activated:Connect(mine)

If it was not understood, let me know I really need to solve this problem, its the only thing missing to publish my game (the output doesnt give errors)

You’re doing this on the client side, you have a server script that will not be able to detect when you’re actually clicking the Tool

Use a RemoteEvent instead, instead of cloning the Tool in your LocalScript, call FireServer() instead :wink:

Then have another script inside ServerScriptService that will properly detect when FireServer() is called to properly clone the Tool

1 Like

I had done that with another game and it worked, the weird thing is that with the mystery box script it detects when I click (and it also clones it), but that is another question, thanks :slight_smile:

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