I’m trying to create a block that awards all players standing on it 5 Xp every 5 seconds, but when I try to detect the players currently standing on the brick and award them it won’t work. I’ve tried just giving the local player Xp and it also doesn’t work.
local AFKZone = script.Parent
local coolDownTime = 5
local PlayerWhoTouched = {}
AFKZone.Touched:Connect(function(other)
if other:IsA("Player") then
PlayerWhoTouched[other] = true
end
end)
while true do
wait(coolDownTime)
for player in pairs(PlayerWhoTouched) do
local character = player.Character
if character then
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
local touchingParts = humanoidRootPart:GetTouchingParts()
local isOnAFKZone = false
for _, part in pairs(touchingParts) do
if part == AFKZone then
isOnAFKZone = true
break
end
end
if isOnAFKZone then
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local Xp = leaderstats:FindFirstChild("Xp")
if Xp then
Xp.Value = Xp.Value + 5
end
end
else
PlayerWhoTouched[player] = nil
end
end
end
end
end