what? No your mining tool is damaging the block, there is a piece of code doing that for you
main problem is each rock waits till the pickaxe hits it and finds a value within the pickaxe called ādamageā and minuses its health with the damage value.
Health = Health - Damage
the script within the pickaxe only manages its animations, as well its mining speed.
hereās what the pickaxe looks like
is the script local or server sided also this:
Rock.Health.Changed:Connect(function()
makes me think that it doesnāt rely on a remote event.
can you send me this code and also tell me if its server or local script
Hereās the image
Hereās the Rockās Script
--Services
local ss = game:GetService("ServerStorage")
local sss = game:GetService("ServerScriptService")
--LootTable
local Common = 1000 --1
local Uncommon = 500 --2
local Rare = 200 --3
local UltraRare = 35 --4
local Legendary = 10 --5
local Mythic = 0.2 --6
local Drops = {
--Ores
--Common
{Name = "Coal"},
{Name = "Copper"},
{Name = "Iron"},
{Name = "Lead"},
{Name = "Tin"},
--Uncommon
{Name = "Amber"},
{Name = "Gold"},
{Name = "Platinum"},
{Name = "Sapphire"},
{Name = "Topaz"},
{Name = "Tungesten"},
--Rare
{Name = "Cobalt"},
{Name = "Diamond"},
{Name = "Emerald"},
{Name = "Garnet"},
{Name = "Onyx"},
{Name = "Ruby"},
{Name = "SkyBlueTopaz"},
--Crystals
--Uncommon
{Name = "Sapphire Crystal"},
{Name = "Rhodolite"},
{Name = "Amethyst Crystal"},
--Rare
{Name = "Clear Quartz"},
{Name = "Sky Blue Topaz"},
--UltraRare
{Name = "Amethyst Airs Quartz"},
{Name = "Crystallized Diamond"},
{Name = "Crystallized Emerald"},
{Name = "Black Kinitaenite"},
{Name = "Spessartite Garnet"},
--Legendary
{Name = "Enchanted Luzi"},
{Name = "Enchanted Rose Qaurtz"},
{Name = "Hallowed Crystal"},
}
local OreLootTable = {
--Common Drops
{Item = Drops[1], Weight = Common}, --Coal
{Item = Drops[2], Weight = Common}, --Copper
{Item = Drops[3], Weight = Common}, --Iron
{Item = Drops[4], Weight = Common}, --Lead
{Item = Drops[5], Weight = Common}, --Tin
--Uncommon Drops
{Item = Drops[6], Weight = Uncommon}, --Amber
{Item = Drops[7], Weight = Uncommon}, --Gold
{Item = Drops[8], Weight = Uncommon}, --Platinum
{Item = Drops[9], Weight = Uncommon}, --Sapphire
{Item = Drops[10], Weight = Uncommon}, --Topaz
{Item = Drops[11], Weight = Uncommon}, --Tungesten
--Rare Drops
{Item = Drops[12], Weight = Rare}, --Cobalt
{Item = Drops[13], Weight = Rare}, --Diamond
{Item = Drops[14], Weight = Rare}, --Emerald
{Item = Drops[15], Weight = Rare}, --Garnet
{Item = Drops[16], Weight = Rare}, --Onyx
{Item = Drops[17], Weight = Rare}, --Ruby
{Item = Drops[18], Weight = Rare}, --Sky Blue Topaz
}
local CrystalLootTable = {
--Uncommon Drops
{Item = Drops[19], Weight = Uncommon}, --Sapphire Crystal
{Item = Drops[20], Weight = Uncommon}, --Rhodolite
{Item = Drops[21], Weight = Uncommon}, --Amethyst Crystal
--Rare Drops
{Item = Drops[22], Weight = Rare}, --Clear Quartz
{Item = Drops[23], Weight = Rare}, --Sky Blue Topaz
}
for i,Rock in pairs((script.Parent:GetChildren())) do --Will Get all of the Rocks
if(Rock:IsA("BasePart")) then --Will Test if the Rock is a Part
if(Rock:FindFirstChild("Health"))then
local label = Rock.HealthInfo
local hit_sound = Rock.Parent.Hit
local rockPos = Rock.Position
local Health = Rock.Health
local MaxHealth = Rock.MaxHealth
local RockMined = Rock.Mined.Value
local debounce = false
--Mining Manager
Rock.Touched:Connect(function(otherPart)
local tool = otherPart.Parent
if tool:IsA('Tool') and tool.Mining.Value == true then
if debounce == false then
debounce = true
local damage = tool.Damage.Value
hit_sound:Play()
Health.Value = Health.Value - damage
label.TextLabel.Text = Health.Value.."/"..MaxHealth.Value
if Rock.Health.Value <= 0 then
if RockMined == false then
RockMined = true
local stone = ss.Drops.Normal:WaitForChild("Stone")
--Stone Generator
for i = 1, math.random(1,4) do --Grabs a random number between 1-4 and begins a loop
local clone = stone:Clone() --Clones the Stone 1-4 times
clone.Parent = workspace --The Cloned Stones appear in the Workspace
if clone:IsA("Model")then
clone.PrimaryPart.Position = rockPos --The Clones Stones will appear at the rock that was mined
elseif clone:IsA("BasePart")then
clone.Position = rockPos --The Clones Stones will appear at the rock that was mined
end
end
if Rock.Variety.Value == "Normal" then
local function returnSumOfWeight(OreLootTable)
local sum = 0
for _, entry in pairs(OreLootTable) do
sum = sum + entry.Weight
end
return sum
end
local function getRandomItem(OreLootTable)
local randomNumber = math.random(returnSumOfWeight(OreLootTable))
for _, entry in ipairs(OreLootTable) do
if randomNumber <= entry.Weight then
return entry.Item
else
randomNumber = randomNumber - entry.Weight
end
end
end
--Crystal/Ore Generator
local RandomItem = getRandomItem(OreLootTable)
local Item = ss.Drops.Ores:FindFirstChild(RandomItem.Name)
for i = 1, math.random(1,3) do --Grabs a random number between 1-3 and begins a loop
local clone = Item:Clone() --Clones the Ores/Crystals 1-3 times
clone.Parent = workspace --The Cloned Ores/Crystals appear in the Workspace
clone.Position = rockPos --The Clones Ores/Crystals will appear at the rock that was mined
end
elseif Rock.Variety.Value == "Crystal" then
local function returnSumOfWeight(CrystalLootTable)
local sum = 0
for _, entry in pairs(CrystalLootTable) do
sum = sum + entry.Weight
end
return sum
end
local function getRandomItem(CrystalLootTable)--Grabs a random Item from the crystal loot table
local randomNumber = math.random(returnSumOfWeight(CrystalLootTable))
for _, entry in ipairs(CrystalLootTable) do
if randomNumber <= entry.Weight then
return entry.Item
else
randomNumber = randomNumber - entry.Weight
end
end
end
--Crystal/Ore Generator
local RandomItem = getRandomItem(CrystalLootTable) --Grabs a random item from the table
local Item = ss.Drops.Crystals:FindFirstChild(RandomItem.Name) --Finds the random item from the table in ServerStorage
for i = 1, math.random(1,3) do --Grabs a random number between 1-3 and begins a loop
local clone = Item:Clone() --Clones the Ores/Crystals 1-3 times
clone.Parent = workspace --The Cloned Ores/Crystals appear in the Workspace
if clone:IsA("Model")then--Will test if the crystal is a model
clone.PrimaryPart.Position = rockPos --The Clones Ores/Crystals will appear at the rock that was mined
elseif clone:IsA("BasePart")then --Will test if the crystal is a part
clone.Position = rockPos --The Clones Ores/Crystals will appear at the rock that was mined
end
end
end
end
end
wait(0.05)
debounce = false
end
end
end)
Rock.ClickDetector.MouseHoverEnter:Connect(function(player)
game:GetService("ReplicatedStorage").RemoteFunctions.EnableGui:InvokeClient(player, Rock, true)
end)
Rock.ClickDetector.MouseHoverLeave:Connect(function(player)
game:GetService("ReplicatedStorage").RemoteFunctions.EnableGui:InvokeClient(player, Rock, false)
end)
Health:GetPropertyChangedSignal("Value"):Connect(function()
if (Health) then
label.TextLabel.Text = Health.Value.."/"..MaxHealth.Value
end
end)
label.TextLabel.Text = Health.Value.."/"..MaxHealth.Value
end
end
end
this is where you need to apply tagāthis is just from a glance
where is the origin of health?
Health.Value = Health.Value - damage
The orgin of the health is in each seperate rock, mainly each one being an int value. Here is the picture of it.
okay just making sure cause I donāt see it assigned (actually now I see it, is under the initial for loop)
ok so from the tag code, this is where you would make a new tag yes?
then from the changed event, the event will fire when it <=0, have the detecting code where you grant xp, destroy the block instead of whatever you have currently (im not sure how you deal with mined blocks)
and then have a local variable playerName = health.parent.creatortag.value and then give exp according to the playername
(also should note to remove the detection from player added if you havenāt already
also might consider doing an on added event if you spawn new blocks. again idk how you have it working)
hoped you solved it let me know if you had issues
I think I get it, the situation is like a player that joined into a game WHICH for a specific player, so each player has there own script, and when the rockās health is less than 0. It will give to all player.
Ok so I tried to add the tag into the script that deals with the rocks health but that didnāt work. I donāt where I needed to put the tag, do I need to put it in the tool and look for the tag in there?
put the code right under where youāre changing the rocks health value
parent the tag to the rock in question
in server, have the detection seperated from playeradded and do health.parent.tag to get the tag then make a local variable playername = tag.value (assuming tag.value is = playername)
from there you should be able to assign xp
it also wouldnāt hurt to send in the tag code you made
try this instead of PlayerAdded:Connect(function(player)
local function GivePlayersEXP()
for i, player in pairs(game.Players:GetPlayers()) do
local LevelStats = player:FindFirstChild("LevelStats")
local exp = LevelStats:FindFirstChild("Current")
if LevelStats and exp then
local randomExp = math.random(5,15)
exp.Value = exp.Value + randomExp
end
end
end
for i, Rock in pairs(ResourceSystem.Rocks:GetChildren()) do
if Rock.Name == "Normal Rock" then
Rock.Health.Changed:Connect(function()
if Rock.Health.Value <= 0 then
print("Rock Mined!")
GivePlayersEXP()
spawn(function()
Rock.Parent = game:GetService("ServerStorage").Resources:FindFirstChild(Rock.Name)
Rock.Mined.Value = false
Rock.Health.Value = 100
wait(respawnTime.Value)
Rock.Parent = workspace.ResourceSystem.Rocks
end)
end
end)
end
end
oh wait I misunderstood your post
give me 1 min
just btw that still makes it to where everyone gets xp but OP you should get a general idea
all you would need to add is to find creator tag, and then send it to the exp function and if game.players:findfirstchild(āplayernameā) doā¦
yeah I misunderstood his post
here is the GiveExp server script:
local function GivePlayersEXP(v)
local player = game.Players:FindFirstChild(v.Name)
if player then
local LevelStats = player:FindFirstChild("LevelStats")
local exp = LevelStats:FindFirstChild("Current")
if LevelStats and exp then
local randomExp = math.random(5,15)
exp.Value = exp.Value + randomExp
end
end
end
for i, Rock in pairs(ResourceSystem.Rocks:GetChildren()) do
if Rock.Name == "Normal Rock" then
Rock.Health.Changed:Connect(function()
if Rock.Health.Value <= 0 then
print("Rock Mined!")
local playersHasMined = Rock:FindFirstChild("Folder")
for i,v in pairs(playersHasMined:GetChildren()) do
GivePlayersEXP(v)
end
spawn(function()
Rock.Parent = game:GetService("ServerStorage").Resources:FindFirstChild(Rock.Name)
Rock.Mined.Value = false
Rock.Health.Value = 100
wait(respawnTime.Value)
Rock.Parent = workspace.ResourceSystem.Rocks
end)
end
end)
end
end
give me 1 min i will also edit your rocks Script
ok I get it now, imma add it see if it works out, so question how will i make the value the playerās name if itāll make it where itās everyone in the server?