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

My Obby spawn script has issues updating, please help?

Asked by 4 years ago

So I'm working on this obby spawn and leaderstats script. I haven't added a part where the player is put at the right spawn, this question is about updating what stage the player is on. The system update's perfectly when I step on a different spawn but if I have 2 people join there is a phenomenon where only one person's leaderstats update and they can be updated by anyone else touching a new spawn. Also it appears that if I have everyone press f9, the print checks to make sure the script isn't erroring will only show up in that one person's output status while the rest are blank. Why does this happen? Is there a way I can make this script work properly for each and every player on their own?

spawns = game.Workspace.spawns

game.Players.PlayerAdded:Connect(function(plr)
    wait()
    lead = Instance.new('Folder', plr)
    lead.Name = 'leaderstats'

    stats = Instance.new('Folder', plr)
    stats.Name = "playerstatistics"

    stage = Instance.new('NumberValue', lead)
    stage.Name = "Stage"
    stage.Value = 0



    plr.CharacterAdded:connect(function(chr)
        print(chr.Name)
        if spawns then
            print('check1')
            for i,v in ipairs(spawns:GetChildren()) do
                if v:FindFirstChild('handle') then
                    print('check 2')
                    handle = v.handle
                    handle.Touched:connect(function(hit)
                        print('check 3')
                        if stage.Value + 1 == v.stageval.Value then
                            print('check 4')
                            stage.Value = v.stageval.Value
                        end
                    end)
                    if v.stageval.Value == stage.Value then
                        print('check 5')
                        if chr:FindFirstChild('Torso') then
                            print('check 6')

                        end
                    end 
                end
            end
        end
    end)
end)


Answer this question