Script
local game = game
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
local character = localPlayer.Character
local runService = game:GetService("RunService")
local replicatedStorage = game:GetService("ReplicatedStorage")
runService.RenderStepped:Connect(function()
character = localPlayer.Character
if character:FindFirstChildWhichIsA("Tool") and string.find(string.lower(character:FindFirstChildWhichIsA("Tool").Name), "shovel") then
for _,v in workspace.TreasurePiles:GetChildren() do
if v:GetAttribute("Owner") == localPlayer.UserId then
replicatedStorage.Source.Network.RemoteEvents.Digging:FireServer({["Command"] = "IsInArea",["TargetPileIndex"] = v:GetAttribute("PileIndex"),["State"] = true})
replicatedStorage.Source.Network.RemoteFunctions.Digging:InvokeServer({["Command"] = "DigPile",["TargetPileIndex"] = v:GetAttribute("PileIndex")})
end
end
replicatedStorage.Source.Network.RemoteFunctions.Digging:InvokeServer({["Command"] = "CreatePile"})
end
end)