IntValue not increasing when its supposed to?
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:
01 | local R 2 Workspace = game.Workspace:WaitForChild( "PointsArea" ) |
03 | local PointsR 2 = game.Players.LocalPlayer.PlayerPointsR 2. Value |
09 | for i, v in pairs (R 2 Workspace:GetChildren()) do |
12 | local region = Region 3. new(v.Position - (v.Size/ 2 ),v.Position + (v.Size/ 2 )) |
14 | local parts = game.Workspace:FindPartsInRegion 3 WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants()) |
17 | for _, part in pairs (parts) do |
18 | if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then |
27 | PointsR 2 = PointsR 2 + 1 |
The script (in a separate part) to add the collected points:
01 | local part = script.Parent |
03 | local DataStore 2 = require( 1936396537 ) |
05 | local function onTouch(otherPart) |
06 | local humanoid = otherPart.Parent:FindFirstChild( 'Humanoid' ) |
08 | local player = game.Players:FindFirstChild(otherPart.Parent.Name) |
09 | if player and canGet then |
11 | local teleportpart = script.Parent |
12 | teleportpart.Touched:Connect( function (hit) |
13 | local XPStore = DataStore 2 ( "XP" , player) |
14 | local CoinsStore = DataStore 2 ( "Coins" ,player) |
15 | XPStore:Increment(player.PlayerPoints.Value + player.PlayerPointsR 2. Value) |
16 | CoinsStore:Increment((player.PlayerPoints.Value/ 2 ) + player.PlayerPointsR 2. Value) |
17 | player.PlayerPoints.Value = player.PlayerPoints.Value - player.PlayerPoints.Value |
18 | player.PlayerPointsR 2. Value = player.PlayerPointsR 2. Value - player.PlayerPointsR 2. Value |
19 | local teleportpart = script.Parent |
20 | if hit.Parent.HumanoidRootPart then |
21 | hit.Parent.HumanoidRootPart.Position = Vector 3. new( 25.361 , 12.195 , 61.318 ) |
29 | part.Touched:Connect(onTouch) |
If anyone can help me it will be greatly appreciated! Sorry if this was too lengthy!