Xp given to everyone instead of the one player

So for some odd reason, when I finished my levels system and mining system and tested it out with some friends. instead of the player who mined a rock only getting XP from the rock they mined, it gave to everyone on the server. I feel like it has to deal with the player value in the function. it looks like this PlayerAdded:Connect(function(player). The script is located in server script storage and its name is called “giveXP”

image

Anyone got any ideas, what i did wrong?

1 Like

Lemme guess.

Inside a PlayerAdded connection, you have a remote event .OnServerEvent connection, and you don’t check whether it is the same player.

1 Like

here’s the script.

game.Players.PlayerAdded:Connect(function(player)
	local exp = player:WaitForChild("LevelStats"):WaitForChild("Current")
	
	--Rock Exp Events
	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 randomExp = math.random(5,15)
					exp.Value = exp.Value + randomExp
					
					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 
end)
1 Like

no I didnt use an event whatsoever, i mainly used a for do loop instead.
i posted the script if you need it

1 Like

What script changes Rock.Health?
What you’re doing right now is making the health changed connection for every player

1 Like

its in a seperate script in workspace, the script only messes with the rock’s drops and health though.

1 Like

He is right, you are having to where everyone has the same detection, rather having the server detect when rock health is <=0 and a mining pick making somesort of tag on it for the server to detect who mined it (hopefully you made a tag system to detect who mined the rock im assuming not)

Shouldn’t be too hard to add a tagging system for your mining tool and then checking tag’s name and then award xp to the player’s name from the tag

1 Like

yeah, I didn’t, imma try to add the tag system if see if it works

1 Like

this should help you get a general idea of what tagging is:

1 Like

ok thank you (i had to extend the text)

1 Like

Question, how will i find the tag if the rock isnt a humanoid.

you can parent the tag however you want. if thats what you’re referring to?

ok i looked at another dev forum and i get how to use a tag system now

also check this post he said he made a slight error in the earlier linked post:

so parent it then add it as a debris item (debris means it goes away and in the post its 2 seconds)

1 Like

oh ok, i get it now. Thank you, imma try to add it now, now that i got a good idea of how to use it.

I tried my best, and now it wont give any xp at all now.

Is there a way i can get a local player from a server script or is that not possible in my case, imma try to use an event instead and see if that works.

how are you checking to damage a block then? There should be a parameter given.

I really don’t know, I’m incredibly confused at this point on what to do. and I’m starting to lose hope alittle.

ok i think i may found a solution, i might make a separate script within the rock that’s a local script, it’ll wait till the rock gets damage, if its health is below 0. It will call the event, and activate the function as well as find the local player