New solution based on your clarified problem:
Sorry for my last answer not directly addressing your problem!
Though what you have there is good in theory, sadly, Roblox has no way of automatically detecting if a block is within range of another block (unless you have something that measures distance, like one of the new Constraints, attached).
Considering this, what I'd recommend doing is as follows:
Step 1. Take a list of all the players in the server.
Step 2. Check the distance of their character's base part (HumanoidRootPart) from the brick.
Step 3. Add to the closest player's leaderstats.
To follow these steps:
By calling local playerList = game.Players.GetChildren(), you make a table called Playerlist that will have every player currently in game on it.
Next, you would make a "for" loop, counting through the list of players and checking how far away from the brick each one is.
local playerList = game.Players.GetChildren()
local targetDistance = 100
local closestPlayer = nil
for i = 1, #playerList do
if (playerList[i].Character.HumanoidRootPart.Position - script.Parent.Position).magnitude < targetDistance then
targetDistance = (playerList[i].Character.HumanoidRootPart.Position - script.Parent.Position).magnitude
closestPlayer = playerList[i]
end
if closestPlayer ~= nil then
closestPlayer.leaderstats.Money.Value = leaserstats.Money.Value +1
end
end
I haven't had a chance to test this script live, so sorry if you run into any minor errors.
This segment replaces your two lines that refer to game.Players.LocalPlayer.
Hope this helps!
2 comments
ummmm this is broken?
I can't understand, can you edit what you wrote and be more clear and specific? That's pretty confusing.