Tool from my shop system didn't work

there are 2 pickaxes with the same scripts (they differ only in dmg), but the pickaxe from the starter pack works, but the one from the store does not. Please help.
Thank you!

Script

script.Parent.Hit.OnServerEvent:Connect(function(plr,hit)
	if hit.Rock.Health.Value > 0 then
		local humanoid = script.Parent.Parent.Humanoid
		local char = humanoid.Parent
		humanoid:LoadAnimation(script.Parent.Hitting):Play()
		wait(0.5)
		script.Parent.Handle.Mined:Play()	
		hit.Rock.Health.Value -= 1
	end
end)

localscript

local collect = game:GetService("CollectionService")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local deb = false
script.Parent.Activated:Connect(function()
	local char = plr.Character
	if deb == false then
		local target = mouse.Target
		if target and target.Parent then
			if collect:HasTag(target.Parent,"Ore") then
				if (char.HumanoidRootPart.Position - target.Position).Magnitude <= 5 then
					script.Parent.Hit:FireServer(target.Parent)				
					deb = true
					wait(1.5)
					deb = false
				end
			end
		end
	end
end)

both pickaxes have the same scripts

2 Likes

Can you explain the problem in more details so we can be able to help you :slight_smile:

If the first one works, the second one should not have issues…

If the second pickaxe is added from the store, the issue has to be in the store script itself. Make sure that the store script (the one that clones and gives the gear to the player) is not a LocalScript.

It would be really helpful if you also send the Store script

I hope this helps :slight_smile:

2 Likes

Yes, my ShopScript is local and located in Gui…

local shop = script.Parent
shop.Visible = false
local openShop = game.Workspace.ShopPart
local storage = game:GetService('ServerStorage')
local replStorage = game:GetService('ReplicatedStorage')
local closShop = script.Parent.Xbutton
local buy = script.Parent.BuyButton
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local canShop = true
local pickaxe2 = replStorage.Pickaxe2
local price = pickaxe2.Price.Value


local function showMenu(otherPart)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid and canShop then
		humanoid.WalkSpeed = 0
		canShop = false
		shop.Visible = true
	end
end

local function closeMenu()
	localPlayer.Character.Humanoid.WalkSpeed = 16
	shop.Visible = false
	wait(2)
	canShop = true
end

local function buyPickaxe2()
	local playerStats = localPlayer:FindFirstChild("leaderstats")
	local playerCoin = playerStats:FindFirstChild("Money")
	if playerCoin.Value >= price then 
		playerCoin.Value -= price 
		local humanoid = localPlayer.Character:FindFirstChild("Humanoid")
		local pickaxeClone = pickaxe2:Clone()
		pickaxeClone.Parent = localPlayer.Backpack
	end
end


buy.MouseButton1Click:Connect(buyPickaxe2)
closShop.MouseButton1Click:Connect(closeMenu)
openShop.Touched:Connect(showMenu)

there is script

1 Like

Thats the issue. The client cannot directly clone gears to itself. Thats made for security measures.

Instead, create a RemoteEvent and a server script that handles the gear cloning and fire it from the function in the LocalScript that buys the pickaxe.

If you have questions or something went wrong reply :slight_smile:

2 Likes

Bruh,this is an ez fix

Player.leaderstats.coins value should be on server

And use remote function for this

Remote function : Client to server back to client

First Client,identifying the stuff

Server: minusing the leaderstats coins value

SecondtimeClient :Cloning the model and put it in the player

I hope this helps for u(this should mostly work

1 Like

I created RemoteEvent and new script in ServerScriptService, but now it doesn’t give me the tool and doesn’t take the money.
new shop script

local shop = script.Parent
shop.Visible = false
local openShop = game.Workspace.ShopPart
local replStorage = game:GetService('ReplicatedStorage')
local closShop = script.Parent.Xbutton
local buy = script.Parent.BuyButton
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local canShop = true
local buyPickaxe2 = replStorage:WaitForChild('BuyPickaxe2')

local function showMenu(otherPart)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid and canShop then
		humanoid.WalkSpeed = 0
		canShop = false
		shop.Visible = true
	end
end

local function closeMenu()
	localPlayer.Character.Humanoid.WalkSpeed = 16
	shop.Visible = false
	wait(2)
	canShop = true
end

local function buyTool2()
	buyPickaxe2:FireServer()
end


buy.MouseButton1Click:Connect(buyTool2)
closShop.MouseButton1Click:Connect(closeMenu)
openShop.Touched:Connect(showMenu)

new server script

local replStorage = game:GetService("ReplicatedStorage")
local BuyPickaxe2 = replStorage:WaitForChild("BuyPickaxe2")

local function buyTool2(player)
	local playerMoney = player.leaderstats.Money.Value
	local toolPrice = replStorage.Pickaxe2.Price.Value
	if playerMoney > toolPrice then
		player.leaderstats.Money.Value = playerMoney - toolPrice
		local tool = replStorage.Pickaxe2:Clone()
		tool.Parent = player.Backpack
	end
end

BuyPickaxe2.OnServerEvent:Connect(buyTool2) 

What is this I have never seen this before,this looks wrong

just to make sure, the leaderstats are on the server right?
also, add print statements to see what is and isn’t running

1 Like

leaderstats on server.
I added print, sooo
image
I think problem in this script

local replStorage = game:GetService("ReplicatedStorage")
local remoteEvent2 = replStorage:WaitForChild("RemoteEvent")

local function buyTool2(player)
	local playerMoney = player.leaderstats.Money.Value
	local toolPrice = replStorage.Pickaxe2.Price.Value
	if playerMoney > toolPrice then
		print("CurrentMoney > toolPrice")
		player.leaderstats.Money.Value = playerMoney - toolPrice
		local tool = replStorage.Pickaxe2:Clone()
		tool.Parent = player.Backpack
	end
end

remoteEvent2.OnServerEvent:Connect(buyTool2) 

hmm
try printing the playerMoney and toolPrice variables (before the if statement)

1 Like

image

see, thats the problem, 3 is not greator then 3. the if statement should be checking for >=, not >

1 Like

Its working! Thank you, and thanks to all those who helped.

2 Likes

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