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 4 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:

01local R2Workspace = game.Workspace:WaitForChild("PointsArea")
02 
03local PointsR2 = game.Players.LocalPlayer.PlayerPointsR2.Value
04 
05 
06local Found = false
07 
08while wait(2) do
09 for i, v in pairs(R2Workspace:GetChildren()) do
10 
11  Found = false
12  local region = Region3.new(v.Position - (v.Size/2),v.Position + (v.Size/2))
13 
14  local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
15 
View all 30 lines...

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

01local part = script.Parent
02local canGet = true
03local DataStore2 = require(1936396537)
04 
05local function onTouch(otherPart)
06    local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
07    if humanoid then
08        local player = game.Players:FindFirstChild(otherPart.Parent.Name)
09        if player and canGet then
10            canGet = false
11local teleportpart = script.Parent
12            teleportpart.Touched:Connect(function(hit)
13                local XPStore = DataStore2("XP", player)
14                local CoinsStore = DataStore2("Coins",player)
15                XPStore:Increment(player.PlayerPoints.Value + player.PlayerPointsR2.Value)
View all 29 lines...

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

Answer this question