#Problems with IncrementPoints

1 messages · Page 1 of 1 (latest)

quasi birch
#

lua```

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local AfkPoints = Instance.new("IntValue")
AfkPoints.Name = "Time"
AfkPoints.Value = 0
AfkPoints.Parent = leaderstats

local Rebirth = Instance.new("IntValue")
Rebirth.Name = "Rebirth"
Rebirth.Value = 0
Rebirth.Parent = leaderstats

while true do 
    wait(1)
    AfkPoints.Value = AfkPoints.Value + 1
end

local Rebirth = Instance.new("IntValue")
Rebirth.Name = "Rebirth"
Rebirth.Value = 0
Rebirth.Parent = leaderstats

end)

local Boxes = game.Workspace.ValueChanger:WaitForChild("Point")
local coins = Boxes:WaitForChild("Time")

for _, Point in pairs(coins:GetChildren()) do
Point.Touched:Connect(function(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
local touched = Boxes.Touched:FindFirstChild("Touched")

    if humanoid and player and touched and touched == false then
        
        touched.Value = true
        
        player.leaderstats.Time.Value += 10
        
        Boxes.Transparency = 0.5
        
    end
    
end)

end

#

so my problems is the increment value of my part being touched

#

Infinite yield possible on 'Workspace.ValueChanger.Point:WaitForChild("Time")' - Studio

#

this is what is says in output

gentle grove
#

Time

#

Is in leaderstats

#

Not point

quasi birch
gentle grove
quasi birch
final kestrel
quasi birch
#

Im a beginner evilcat

final kestrel
#

Your trying to find a nonexistsent instance in workspace

#

when you created an instance inside a player (leaderstats)

#

if your doing this in server, itssss gonna be kindof confusing

#

in a local script

#

you can just do a Players.LocalPlayer. ...

#

and find the Value From there

gentle grove
#

To use

#

Local script

#

For that

final kestrel
quasi birch
gentle grove
final kestrel
#

cause it wouldnt even work, servers wont even see the changes

#

my fault on that

#

but

quasi birch
#

so the part of the code not working is that one :

#

lua```

 local Boxes = game.Workspace.ValueChanger:WaitForChild("Point")

local coins = Boxes:FindFirstChild("leaderstats")

for _, Point in pairs(coins:GetChildren()) do
Point.Touched:Connect(function(otherPart)
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
local touched = Point.Touched:FindFirstChild("Touched")

    if humanoid and player and touched and touched == false then
        
        touched.Value = true
        
        player.leaderstats.Time.Value += 10
        
        Boxes.Transparency = 0.5
        
    end
    
end)

end ```

final kestrel
#
local Boxes = game.Workspace.ValueChanger:WaitForChild("Point")

local coins = Boxes:FindFirstChild("leaderstats")

for _, Point in pairs(coins:GetChildren()) do
    Point.Touched:Connect(function(otherPart)
        local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
        local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
        local touched = Point.Touched:FindFirstChild("Touched")
        
        if humanoid and player and touched and touched == false then
            
            touched.Value = true
            
            player.leaderstats.Time.Value += 10
            
            Boxes.Transparency = 0.5
            
        end
        
    end)
end   

dont mind me js gonna do this

quasi birch
final kestrel
#

Time is nowhere found inside Boxes

#

another issue is

#

local coins = Boxes:WaitForChild("Time")

#

wait

#

waait

#

wrong one

#

local touched = Point.Touched:FindFirstChild("Touched")

#

this one

#

What the hell is this?

#

Are you trying to find an instance named Touched?

quasi birch
final kestrel
#

If your only trying to find an boolval inside of Point

sour tinselBOT
#

studio** You are now Level 7! **studio

final kestrel
# quasi birch Point is my part

Yeah, you wouldnt need local touched = Point.Touched:FindFirstChild("Touched") overall IF your only trying to find a boolvalue named touched.

quasi birch
#

Even with a GetService from leaderstats it doest find the Value

I verified with a statement

quasi birch
#

Nah i mean to call the leaderstats folder

final kestrel
# quasi birch Nah i mean to call the leaderstats folder
game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local AfkPoints = Instance.new("IntValue")
    AfkPoints.Name = "Time"
    AfkPoints.Value = 0
    AfkPoints.Parent = leaderstats

    local Rebirth = Instance.new("IntValue")
    Rebirth.Name = "Rebirth"
    Rebirth.Value = 0
    Rebirth.Parent = leaderstats

    while true do 
        wait(1)
        AfkPoints.Value = AfkPoints.Value + 1
    end -- what the hell is up with this LOL???? this would give points EVEN if the player isnt afk. fix your shit.

    local Rebirth = Instance.new("IntValue")
    Rebirth.Name = "Rebirth"
    Rebirth.Value = 0
    Rebirth.Parent = leaderstats

end)

local Boxes = game.Workspace.ValueChanger:WaitForChild("Point")
local coins = Boxes:WaitForChild("Time") -- Make sure theres a instance named "TIME" bro.
-- whats up with the naming anyways? Coins -> Time???? weird.

for _, Point in pairs(coins:GetChildren()) do
    Point.Touched:Connect(function(otherPart)
        local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
        local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
        local touched = Boxes:FindFirstChild("Touched") -- Boxes.Touched:FindFirstChild would hit you with an error.
        
        if humanoid and player and touched and touched == false then
            
            touched.Value = true
            
            player.leaderstats.Time.Value += 10
            
            Boxes.Transparency = 0.5
            
        end
        
    end)
end   
#

did you use ai for this?

inland karma
#

yo

#

whats popping

quasi birch
final kestrel
#

can you like

quasi birch
#

Not at all

final kestrel
#

help him instead

quasi birch
final kestrel
#

im genuienly

#

so CONFUSED

#

😭

inland karma
#

is that a server script?

final kestrel
#

depends on him

#

hes using local touched = Point.Touched:FindFirstChild("Touched") though

#

LMAO

#

😭

inland karma
#

wtf

#

thats not even valid

#

thats cowshit

final kestrel
#

exactly

#

😭

inland karma
#

OP u here?

#

OP?

quasi birch
#

Yeah basically it has the players stats for server like each second = +1 and then if i touch that part it will give me 10+

quasi birch
inland karma
#

use this script instead

#

omg...

sour tinselBOT
#

studio** You are now Level 7! **studio

quasi birch
inland karma
#
game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local time = Instance.new("IntValue", leaderstats)
    time.Name = "Time"
    time.Value = 0

    local rebirth = Instance.new("IntValue", leaderstats)
    rebirth.Name = "Rebirth"
    rebirth.Value = 0

    task.spawn(function()
        while player.Parent do
            task.wait(1)
            time.Value += 1
        end
    end)
end)

local coins = game.Workspace:WaitForChild("ValueChanger"):WaitForChild("Point"):WaitForChild("Time")

for _, point in pairs(coins:GetChildren()) do
    local touchedFlag = Instance.new("BoolValue", point)
    touchedFlag.Name = "Touched"
    touchedFlag.Value = false

    point.Touched:Connect(function(hit)
        local char = hit.Parent
        local player = game.Players:GetPlayerFromCharacter(char)
        local humanoid = char and char:FindFirstChild("Humanoid")

        if player and humanoid and not touchedFlag.Value then
            touchedFlag.Value = true

            local stat = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Time")
            if stat then
                stat.Value += 10
            end

            point.Transparency = 0.5

            task.delay(3, function()
                touchedFlag.Value = false
                point.Transparency = 0
            end)
        end
    end)
end
final kestrel
#

spoonfeeding him atp

#

😭

inland karma
#

OP, just copy and paste

#

problem solved

quasi birch
#

thanks but can you explain to me what i did wrong in my code please ?

final kestrel
#
  • local touched = Point.Touched:FindFirstChild("Touched") is not valid
celest junco
#

Do u understand the use of find first child

quasi birch
#

And it didnt worked it still says Infinite Yield possible on 'Workspace.ValueChanger.Point:WaitForChild("Time")

final kestrel
#
  • AFKPoints gives out Values even if not afk
quasi birch
quasi birch
celest junco
#

Look in your workspace

#

Is Time a child of Point

#

Time is a child of leaderstats

#

Right

quasi birch
celest junco
#

Do you know what findfirstchild does

quasi birch
#

It basically find the first thing in the Folder or in the item right ? And WaitForChild finds it between multiple things ?

celest junco
#

Yes

#

First instance of that name

#

So is time even a child of Point

#

In your workspace

quasi birch
#

Nah time is in leaderstats Folder

#

Not in workspace

#

I created the leaderstats folder higher in the code

celest junco
#

Are you even using coins

#

Why is that the reference to coins

#

Just change it to leaderstats:FindFirstChild(‘Time’)

quasi birch
#

Where should i put it ?

celest junco
#

Do u understand a single thing about your code

quasi birch
#

I got it i think wait

quasi birch
celest junco
#

Send it

#

Well yeah

#

Who even wrote this

#

There can’t be any children of an intvalue

quasi birch
#

Sorry i cant edit it with the

lua```

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"

local time = Instance.new("IntValue", leaderstats)
time.Name = "Time"
time.Value = 0

local rebirth = Instance.new("IntValue", leaderstats)
rebirth.Name = "Rebirth"
rebirth.Value = 0

task.spawn(function()
    while player.Parent do
        task.wait(1)
        time.Value += 1
    end
end)

local coins = leaderstats:FindFirstChild(time)
local part = game.Workspace.ValueChanger.Point
for _, coins in pairs(coins:GetChildren()) do
local touchedFlag = Instance.new("BoolValue", part)
touchedFlag.Name = "Touched"
touchedFlag.Value = false

part.Touched:Connect(function(hit)
    local char = hit.Parent
    local player = game.Players:GetPlayerFromCharacter(char)
    local humanoid = char and char:FindFirstChild("Humanoid")

    if player and humanoid and not touchedFlag.Value then
        touchedFlag.Value = true

        local stat = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Time")
        if stat then
            stat.Value += 10
        end

        part.Transparency = 0.5

        task.delay(3, function()
            touchedFlag.Value = false
            part.Transparency = 0
        end)
    end
end)

end
end)

quasi birch
celest junco
#

I told u

quasi birch
#

So instead of GetChildren i just putted for part, coins in pairs (leaderstats, coins) do but doesnt work, did i did it wrong ?

#

heres what it shows me now

#

argument #1 expects a string, but Instance was passed - Serveur - ValueIncrement:21
18:18:40.011 Stack Begin - Studio
18:18:40.011 Script 'Workspace.ValueChanger.Point.ValueIncrement', Line 21 - Studio - ValueIncrement:21
18:18:40.011 Stack End - Studio
18:18:40.011 Workspace.ValueChanger.Point.ValueIncrement:23: invalid argument #1 to 'pairs' (table expected, got Instance)

quasi birch
warped oasis
quasi birch
#

Hold on imma send you my script

warped oasis
#

@quasi birch

quasi birch
warped oasis
quasi birch
#

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"

    local time = Instance.new("IntValue", leaderstats)
    time.Name = "Time"
    time.Value = 0

    local rebirth = Instance.new("IntValue", leaderstats)
    rebirth.Name = "Rebirth"
    rebirth.Value = 0

    task.spawn(function()
        while player.Parent do
            task.wait(1)
            time.Value += 1
        end
    end)


local coins = leaderstats:FindFirstChild(time)
local part = game.Workspace.ValueChanger.Point
for part, coins in pairs(coins, coins) do
    local touchedFlag = Instance.new("BoolValue", part)
    touchedFlag.Name = "Touched"
    touchedFlag.Value = false

    part.Touched:Connect(function(hit)
        local char = hit.Parent
        local player = game.Players:GetPlayerFromCharacter(char)
        local humanoid = char and char:FindFirstChild("Humanoid")

        if player and humanoid and not touchedFlag.Value then
            touchedFlag.Value = true

            local stat = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Time")
            if stat then
                stat.Value += 10
            end

            part.Transparency = 0.5

            task.delay(3, function()
                touchedFlag.Value = false
                part.Transparency = 0
            end)
        end
    end)
end
end)

quasi birch
warped oasis
#

ok so i found a few issues

warped oasis
quasi birch
warped oasis
#

leaderstats must be parented to the player (leaderstats.Parent = player), not just created without a proper parent.

When finding the Time value, use a string key: leaderstats:FindFirstChild("Time"), not the variable time.

The loop for part, coins in pairs(coins, coins) do makes no sense since you only work with one part — no loop is needed.

The debounce (touchedFlag) should be unique per player, not shared on the part, otherwise multiple players stepping on the part might not get points properly.

Creating touchedFlag as a BoolValue inside the part is unnecessary and less clean — better to use a local debounce variable inside the script.

#

the issues

#

lemme update the script

warped oasis
#

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local time = Instance.new("IntValue")
time.Name = "Time"
time.Value = 0
time.Parent = leaderstats

local rebirth = Instance.new("IntValue")
rebirth.Name = "Rebirth"
rebirth.Value = 0
rebirth.Parent = leaderstats

local part = workspace.ValueChanger.Point
local debounce = false

part.Touched:Connect(function(hit)
    local char = hit.Parent
    local player = game.Players:GetPlayerFromCharacter(char)
    local humanoid = char and char:FindFirstChild("Humanoid")
    if player and humanoid and not debounce then
        debounce = true
        local stat = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Time")
        if stat then
            stat.Value += 10
        end
        task.delay(3, function()
            debounce = false
        end)
    end
end)

end)

#

@quasi birch does it work

quasi birch
#

Ill try

warped oasis
quasi birch
#

Alr it works thanks

#

So much complications

warped oasis
quasi birch
#

Alr i send u a msg and if in case i need help ill ask you

#

And thanks again 🫡

warped oasis
celest junco
#

when u create the instance, the second argument is the parent

#

local leaderstats = Instance.new(“Folder”, player)

#

this makes the parent of the instance player

warped oasis
gentle grove
#

Is that ai response

warped oasis
final kestrel
#

How do u type "—"

#

LOL

#
  • _ —
#

9h wait

#

I see

warped oasis
#

What the hell u mean How do u type "—"