Xp given to everyone instead of the one player

and here is the rocks 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
						
						local playersHasMined = Rock:FindFirstChild("Folder") or Instance.new("Folder",Rock)	
						local playervalue = playersHasMined:FindFirstChild(tool.Parent.Name) or Instance.new("BoolValue",Rock)
						playervalue.Name = tool.Parent.Name
					
						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
2 Likes
Update 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()
					playersHasMined:Destroy()
					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
2 Likes

ok so i added the new script in, imma test play it see if it works.

1 Like

so on the server script, the function doesn’t seem to be going off. every time I mine a rock it doesn’t give me xp and i tried to add a print value to print the player’s name in the function, i got nothing when i mined the rock. There is no errors in output either.

1 Like

can you add a print value to print the player’s name in the Rock Script

just add here

Print(tool.Parent.Name)

So it printed out my name meaning the rock script works besides the xp script

Switch the command GivePlayersEXP to

local function GivePlayersEXP(v)
	print(v.Name)
	local player = game.Players:FindFirstChild(v.Name)
	if player then
		local LevelStats = player:FindFirstChild("LevelStats")
		local exp = LevelStats.Current
		local randomExp = math.random(5,15)
		exp.Value = exp.Value + randomExp
	end
end

And look at the output

30

i still got nothing in the output besides my name.

which script printed your name

the rock script (the script this isn’t in serverscriptservice)

1 Like

can i get access to your game?

yeah sure. Ill give you the file in a second.

here’s the place
Ignore everything, in serverscriptservice you’ll see the giveXP script in the levelsystem folder, and you’ll see 4 pickaxes lined up infront of some parts, those parts are the rocks and their in a folder called “Rocks” in the ResourceSystem Folder in Workspace.
Test Realm.rbxl (1.2 MB)

1 Like

there is no folder called “LevelStats” how so?

image

Well I found the problem

30

replace the Rock Script to

--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

						local playersHasMined = Rock:FindFirstChild("Folder") or Instance.new("Folder",Rock)	
						local playervalue = playersHasMined:FindFirstChild(tool.Parent.Name) or Instance.new("BoolValue",playersHasMined)
						playervalue.Name = tool.Parent.Name
						
					
						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
1 Like

It worked thank yall so much for your help! I wouldn’t have ever figured out how to fix this without yalls help!

1 Like