So I’ve made script where the value of your local player changes when you explode a brick and then that gets added to your local player num value which is made and put in your local player when he joins.
But when a player destroys a brick it goes to count to everyones local num value I have speculations it’s because I may call the function wrong.
explosion.Hit:Connect(function(Num)
local Bricks = {Num}
for i,v in pairs(Bricks) do
if Num.Anchored == true then
print("Model")
else
for _,player in pairs(game.Players:GetPlayers()) do
if Num:IsDescendantOf(player.Character) then
print("Human")
else
game.Workspace.RedScore.Value = game.Workspace.RedScore.Value + 1
game.Players.LocalPlayer.Stats.Value = game.Players.LocalPlayer.Stats.Value + 1
end
end
end
end
end)
wait(3)
end```
I assume this is client code? If that’s the case, you’re going to want to call a RemoteEvent to the server to properly update the RedScore value, otherwise that change will only be evident for the player who changed it’s value (assuming that’s not your intention.)
If this is server code, then you don’t have access to the LocalPlayer and therefor this code would throw an error upon execution.
I’ve rewritten your code, I’d recommend creating a server script and not doing this on the client:
local hits = {}
explosion.Hit:Connect(function(hit_part)
if hit_part.Parent and hit_part.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild(hit_part.Parent.Name) and not hits[hit_part.Parent] then
hits[hit_part.Parent] = true
local player = game.Players[hit_part.Parent.Name]
workspace.RedScore.Value = workspace.RedScore.Value + 1
player.Stats.Value = player.Stats.Value + 1
end
end)
I’m really unsure of what you’re trying to achieve here, as the way your current code is set up I really can’t see this working at all, you’ll also run into issues with client-server replication, assuming you’re changing those values client-sided and you wish for those changes to be replicated as well.