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”
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)
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
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.
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