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)
Can you explain the problem in more details so we can be able to help you
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
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)
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
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)
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)