#My Script is low Key buggin

1 messages · Page 1 of 1 (latest)

mystic bridge
#

Help

#

Code:

#

the output is only ment to print the cash added and max cash once.

next quest
#

Script low key buggin is one way to start a post

#

doesnt part.Touched:Connect(onTouch) starts addcash

#

why call it again in part.Touched:Connect(addCash)

#

?

mystic bridge
#

Didn’t see that, will check when I get back to my setup

mystic bridge
#

still getting the same results

next quest
#
        char = player.Character

        if char and DB == false then
            DB = true
            createValues(char)
            addCash()
            UI.Background.Visible = true
            task.wait()
        end
    end``` this part of the script works, and prints the thing once
#

this is the problem

#
            local char = part.Parent
            local player = Players:GetPlayerFromCharacter(char)

            if char then
                local currentCash = char:FindFirstChild("currentCash") or char:WaitForChild("currentCash")
                local doneCollecting = char:FindFirstChild("doneCollecting") or char:WaitForChild("doneCollecting")

                task.wait(4)

                if currentCash and doneCollecting then
                    currentCash.Value = currentCash.Value + 1000
                    
                    task.wait(1.5)
                    print("Cash Added!")

                    if currentCash.Value >= 5000 then
                        doneCollecting.Value = true
                        currentCash.Value = 5000
                        print("Max Cash!")
                        
                    end
                end
            end
        end
#

so basically if the part is touching the legs and arms of the players, since the player has 2 legs and 2 arms, it is going to do it 4 times

#

and print it 4 times

#

cause you are looping through the parts, and getting the character

#

local function addCash()
    while true do

        local playerList = part:GetTouchingParts()
        local loopedThroughplayers = {}
        for _, part in ipairs(playerList) do
            local char = part.Parent
            local player = Players:GetPlayerFromCharacter(char)
            if loopedThroughplayers[player.Name] then continue end
            loopedThroughplayers[player.Name] = player
            if char then
                local currentCash = char:FindFirstChild("currentCash") or char:WaitForChild("currentCash")
                local doneCollecting = char:FindFirstChild("doneCollecting") or char:WaitForChild("doneCollecting")

                task.wait(4)

                if currentCash and doneCollecting then
                    currentCash.Value = currentCash.Value + 1000

                    task.wait(1.5)
                    print("Cash Added!")

                    if currentCash.Value >= 5000 then
                        doneCollecting.Value = true
                        currentCash.Value = 5000
                        print("Max Cash!")

                    end
                end
            end
        end
    end
end


#

here is a modified script that makes sure the player hasnt got the cash before

#

checks if the player isnt in loopedThroughplayers table(player that got the cash), and if the player isnt it give the player the cash

#

Hope this works !

mystic bridge
#

got an error

#

ServerScriptService.CollectingCash:37: attempt to index nil with 'Name'

next quest
#

oh sorry mb

#
    while true do

        local playerList = part:GetTouchingParts()
        local loopedThroughplayers = {}
        for _, part in ipairs(playerList) do
            local char = part.Parent
            local player = Players:GetPlayerFromCharacter(char)
        if player == nil then continue end
            if loopedThroughplayers[player.Name] then continue end
            loopedThroughplayers[player.Name] = player
            if char then
                local currentCash = char:FindFirstChild("currentCash") or char:WaitForChild("currentCash")
                local doneCollecting = char:FindFirstChild("doneCollecting") or char:WaitForChild("doneCollecting")

                task.wait(4)

                if currentCash and doneCollecting then
                    currentCash.Value = currentCash.Value + 1000

                    task.wait(1.5)
                    print("Cash Added!")

                    if currentCash.Value >= 5000 then
                        doneCollecting.Value = true
                        currentCash.Value = 5000
                        print("Max Cash!")

                    end
                end
            end
        end
    end
end```
#

i forgot to check if the part is actually a player before searching

mystic bridge
#

no problem

next quest
#

did it work tho

next quest
#

?

mystic bridge
#

it did

#

but it went over 5k

#

but i fixed it

mystic bridge
#

i got another error

#

ServerScriptService.CollectingCash:76: Script timeout: exhausted allowed execution time

spice pier
mystic bridge
#

i got it fixed

next quest
#

yay