The pickaxe I'm working on is supposed to collect gold when the player clicks on the ore, which deletes the ore afterwards and adds money to the leaderboard. This script works in Studio, but not the actual game.
LocalScript inside the tool
local Tool = script.Parent
Tool.Activated:Connect(function()
game.ReplicatedStorage.PickaxeHit:FireServer()
end)
Server Script inside the tool
game.ReplicatedStorage.PickaxeHit.OnServerEvent:Connect(function(player)
local Tool = player.StarterGear:FindFirstChild("GoldPickaxe")
local mouse = player:GetMouse();
local ting = 0
if (mouse.Target.Parent.Name == "GoldOre") then
mouse.Target:Destroy();
local anim = Instance.new("StringValue")
anim.Name = "toolanim"
anim.Value = "Slash"
anim.Parent = Tool
if ting == 0 then
local user = player
local stats = user:findFirstChild("leaderstats")
if stats ~= nil then
local cash = stats:findFirstChild("Gold")
cash.Value = cash.Value +1
end
end
end
end)

2 comments
You shouldn't be getting the mouse on the server.
You can't get mouse from the Server only localPlayer