Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

IntValue not increasing when its supposed to?

Asked by 3 years ago

So I made a region in my game where you get a point every second you stay in it, but I tried to get the script to add the collected points to your XP, but it wont add it for some reason. Here's the code:

The region:

local R2Workspace = game.Workspace:WaitForChild("PointsArea")

local PointsR2 = game.Players.LocalPlayer.PlayerPointsR2.Value


local Found = false

while wait(2) do
 for i, v in pairs(R2Workspace:GetChildren()) do

  Found = false
  local region = Region3.new(v.Position - (v.Size/2),v.Position + (v.Size/2))

  local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())


  for _, part in pairs(parts) do
   if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
    Found = true
    break
   else
    Found = false
   end
  end

  if Found == true then
               PointsR2 = PointsR2 + 1
        end
    end
end

The script (in a separate part) to add the collected points:

local part = script.Parent
local canGet = true
local DataStore2 = require(1936396537)

local function onTouch(otherPart)
    local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
    if humanoid then
        local player = game.Players:FindFirstChild(otherPart.Parent.Name)
        if player and canGet then
            canGet = false
local teleportpart = script.Parent 
            teleportpart.Touched:Connect(function(hit)
                local XPStore = DataStore2("XP", player)
                local CoinsStore = DataStore2("Coins",player)
                XPStore:Increment(player.PlayerPoints.Value + player.PlayerPointsR2.Value)
                CoinsStore:Increment((player.PlayerPoints.Value/2) + player.PlayerPointsR2.Value)
                 player.PlayerPoints.Value = player.PlayerPoints.Value - player.PlayerPoints.Value
                player.PlayerPointsR2.Value = player.PlayerPointsR2.Value - player.PlayerPointsR2.Value
                local teleportpart = script.Parent
                if hit.Parent.HumanoidRootPart then
                    hit.Parent.HumanoidRootPart.Position = Vector3.new(25.361,12.195,61.318)
        end
    end)
end
            canGet = true
        end
    end

part.Touched:Connect(onTouch)

If anyone can help me it will be greatly appreciated! Sorry if this was too lengthy!

Answer this question