Hello!
I wanted to know if I was using maid correctly for my remote function.
local function setOreState(plr, ore, state)
local Maid = maid.new()
if ore ~= nil then
if state ~= 0 and table.find(miningBlocks, ore) then return end
ore:SetAttribute("Mining", state)
if state ~= 0 then
table.insert(miningBlocks, ore)
else
table.remove(miningBlocks, table.find(miningBlocks, ore))
end
for i,v in pairs(ore:GetChildren()) do
if v.Name == "MiningDecal" then
if state == 0 then
v.Transparency =1
else
v.Transparency = (ore:GetAttribute("Health")/100)
end
end
end
task.spawn(function()
if HandlerMod.isInventoryFull(plr) == false then
repeat task.wait(0.1)
if not table.find(miningBlocks, ore) then return end
local damage = HandlerMod.CalculatePickaxeDamage(plr, ore)
if ore ~= nil and damage~=nil then
ore:SetAttribute("Health", ore:GetAttribute("Health") - damage)
end
--game.ReplicatedStorage.Remotes.SetOreHealth:FireServer(part,part:GetAttribute("Health") - damage)
--part:SetAttribute("Health", part:GetAttribute("Health") - damage)
until ore == nil or ore:GetAttribute("Health") <= 0 or not table.find(miningBlocks, ore)
if ore ~= nil and ore:GetAttribute("Health") <= 0 then
if ore ~= lastMIned and ore ~= nil then
lastMIned = ore
MainModule.Generate(plr,ore)
end
end
else
Notifications:SendPlayerNotification(plr, "Error", Color3.fromRGB(222, 0, 4), "You have reached max inventory space. Upgrade your storage for more, or deposit your inventory to mine.", 5)
end
end)
end
Maid:Destroy()
return true
end
game.ReplicatedStorage.Remotes.SetOreState.OnServerInvoke = setOreState
Before the return I use maid:destroy()
local function findOtherBlockBeingMined(userid)
local Maid = maid.new()
local count = 0
for i,v in pairs(game.Workspace.Mine:GetDescendants()) do
if v:GetAttribute("Mining") ~= nil then
if v:GetAttribute("Mining") == userid then
count = count + 1
end
end
end
if count > 1 then
Maid:Destroy()
return true
else
Maid:Destroy()
return false
end
end
Also for this, is this the right way to do it or should I use Maid:GiveTask()?