#Why is this not working

98 messages · Page 1 of 1 (latest)

teal horizon
#

Tryna make an autoclicker system

rocky egret
#

Do you see "No!" printed in the console?

#

I would add more prints to see how far the code is getting to track down where it is failing.

Such as a print after line 62 to make sure you are even calling the function.

Then a print after line 75 to test your member check is working

teal horizon
#

None of these are being printed

rocky egret
#

Do you see "Clicked" ?

glass otterBOT
#

studio** You are now Level 5! **studio

teal horizon
rocky egret
#

Cool, so the problem lies with receiving the server event. When/how does enable.OnServerEvent:Connect(enableButton) get called?

teal horizon
rocky egret
#

but the :Connect function is what binds the button event to the client. So how is that going to get called if you haven't binded the event on the client before?

teal horizon
#

i did bind it

teal horizon
rocky egret
#

Oh sorry I was reading backwards. You are sending an event to the server enable.

Then on the server you want to receive it and call the function enableButton. However, the line that tells the server to call the function enableButton is inside the function enableButton. So it doesn't get bound until enableButton is called at least once.

teal horizon
#

but on my other script its also inside and it works fine

glass otterBOT
#

studio** You are now Level 6! **studio

teal horizon
#

so i should change the local function to a function?

#

nvm

#

let me try if it works after i put it outside

rocky egret
#

progress!

teal horizon
#

in my other function, how does the script know what "player" means if i havent defined it anywhere

#

Hi

rocky egret
#

player must be defined somewhere on a line above onEnd for that one to work

#

sorry, in a meeting can't reply fast

teal horizon
#

its a whole different function

#

I'm gonna off

#

but if anyone wanna help me you can write and i will check later

rocky egret
#

Ah so in the case of onEnd Roblox API PlayerAdded is giving you that reference to the player instance (see parameters). That is how onEnd has access to it. https://create.roblox.com/docs/reference/engine/classes/Players#PlayerAdded

player is only available inside of the function(player) .. end) block of code, it is only available within that scope. See: https://create.roblox.com/docs/luau/scope

You could move your enableButton function inside of that scope. But also notice that OnServerEvent can give you player(the player that sent the event) in the same way that PlayerAdded gives you player: https://create.roblox.com/docs/reference/engine/classes/RemoteEvent#OnServerEvent

teal horizon
#

But what's with the error

#

that i had

rocky egret
teal horizon
#

what should i do

rocky egret
#

change line 62 to local function enableButton(player) to grab the specific player that sent the event out of the OnServerEvent. Then use the player variable inside of your function

teal horizon
#

does the scope reach that far

rocky egret
#

enableButton function has its own scope and we are passing player into it. It is not the same player that onEnd has.

teal horizon
#

so i dont need to define player except for passing it in the function

rocky egret
#

Correct, you can say that OnServerEvent has defined it for you and you are passing it through to your enableButton function

teal horizon
#

ohhhh

#

thanks i'll try it later

#

i haven't slept for 83 hours i'm a bit slow

rocky egret
#

haha you didn't seem slow at all, all good questions

teal horizon
#

lol i'm studying for 4 tests and making game at the same time with 3 screens

#

ty bro

teal horizon
teal horizon
#

Haii

rocky egret
#

Yo, where did you get the code Enum.GroupRole.Member? That doesn't appear to be part of Roblox

teal horizon
#

idk how to check grouprole

#

if theyre in the group atleast

rocky egret
teal horizon
#

but i only want to check if they're in the group not role

rocky egret
#

Okay, the docs say:

The GetRoleInGroup Player function returns the player's role in the group as a string, or Guest if the player isn't part of the group.

So it looks like you can check groupMembership == "Guest" -> they are not in the group

#

I still think it would be valuable to print(groupMembership) and play as a player in the group/not in group to confirm what value you need to use

teal horizon
rocky egret
#

Replace line 71 with if groupMembership ~= "Guest" then

#

That error is telling you Enum.GroupRole.__ doesn't exist, you can't have Enum.GroupRole in your code

teal horizon
#

It works

#

But it isn't stopping when i click it again

#

how do i make it stop when clicked again

rocky egret
#

One approach is to set autoClickerEnabled to false when you click again. But remember the idea of scope. You are declaring a new autoClickerEnabled variable every time you click the button, so each click of the button can't see or change the variable from the last time.

So think about how you can have a shared autoClickerEnabled variable and check it each time you call the function. If it is true then set it false, if it is false then set it true and start looping

#

ANother idea is have the client send the desired true/false in the remoteEvent:

client wants to disable autoclicker:
enable:FireServer(false)

client wants to enable autoclicker:
enable:FireServer(true)

teal horizon
#

maybe local autoclickerdisabled

teal horizon
#

but i maybe need another remoteevent for when i disable

rocky egret
#

Close, I mean have the localscript remember if autoclicker is on or off, so each time you click you tell the server you want it to become opposite.

local isAutoClickerEnabled = false
button.MouseButton1Click:Connect(function()
    isAutoClickerEnabled = not isAutoClickerEnabled -- if true it becomes false, if false it becomes true
    enable:FireServer(isAutoClickerEnabled)
    print("sent autoClickerEnabled", isAutoClickerEnabled)
end)
teal horizon
#

bro

#

my upgrade aint working with autoclicker

#

i had to write it twice in order for it to work with both manual and auto clicking

rocky egret
#

Btw you can paste code in discord with three ticks ```

You've got a lot of moving parts in your script I won't be able to get your entire feature working. I can only offer direction.

You want the autoclicker to run, and then when the user earns an upgrade they should start earning more money from the autoclicker?

The fundamental problem with your approach is you have a while loop created inside the enableButton function. After you call it once and it starts looping it becomes difficult to ever change anything about what the loop is doing.

That video I sent has an approach where the autoclicking while loop lives in the script scope so it can use all the shared variables from the entire script.

teal horizon
#

i made a upgrade system where if you reach 100 value you go to another level manually but it aint working with the autoclicker

#

only if i click manually

#

my whole script broke

#

now it aint changing size

#

now im not gaining anything

#

@outer flare

teal horizon
#

):

#
local part = workspace._PARTS.Part
local originalsize = part.Size
local newsize = Vector3.new(10, 10, 10)
local click = game.ReplicatedStorage.Click
local holdend = game.ReplicatedStorage.HoldEnd
local enable = game.ReplicatedStorage.Enable
local sound = workspace.Click
local plyr = game:GetService("Players")

plyr.PlayerAdded:Connect(function(player)
    local function onRemote()
        part.Size = newsize
        local particle = part.Glitch
        particle.Enabled = true

    end


    local levelUpBlocks = 100
    local function onEnd()
        part.Size = originalsize
        local leaderstats = player:FindFirstChild("leaderstats")
        local luckyBlocks = leaderstats:FindFirstChild("🌈Lucky Blocks")
        local Diamonds = leaderstats:FindFirstChild("Diamonds")
        local currentLevelValue = leaderstats:FindFirstChild("Level")
        
        if leaderstats and leaderstats:FindFirstChild("🌈Lucky Blocks") then
            luckyBlocks.Value = luckyBlocks.Value + (1 * currentLevelValue.Value)
        
        
            if luckyBlocks.Value >= levelUpBlocks and currentLevelValue then
                luckyBlocks.Value = 0
                levelUpBlocks = levelUpBlocks * 2
                currentLevelValue.Value = currentLevelValue.Value + 1
                Diamonds.Value += math.random(1, 1000)
                
                
            if currentLevelValue then
                local newluckyBlocks = luckyBlocks.Value * levelUpBlocks
                luckyBlocks.Value = luckyBlocks.Value + newluckyBlocks
            end

                print("Current Level:", currentLevelValue.Value)

            print("Lucky Blocks:", luckyBlocks, "Level Up Blocks:", levelUpBlocks)
        else
            return luckyBlocks
        end
    end
end
    

    click.OnServerEvent:Connect(onRemote)
    holdend.OnServerEvent:Connect(onEnd)
end)```
#
local function enableButton(player)
    print("Cal")
    local GROUP_ID = 16730316
    
    local groupMembership = player:GetRoleInGroup(GROUP_ID)
    local leaderstats = player:FindFirstChild("leaderstats")
    local luckyBlocks = leaderstats:FindFirstChild(":rainbow:Lucky Blocks")
    local currentLevelValue = leaderstats:FindFirstChild("Level")
    local button1 = game.StarterGui.Coins.Frtame.FreeAuto
    local autoclickerEnabled = false
    local autoclickerDisabled = true




    if groupMembership ~= "Member" then
        print(groupMembership)
        local autoclickerEnabled = true
        local autoclickerDisabled = false
            button1.ImageColor3 = Color3.new(0, 1, 0)
            while autoclickerEnabled do
        luckyBlocks.Value = luckyBlocks.Value + (1 * currentLevelValue.Value)
                wait(0.1)
            end
    elseif groupMembership == nil then
            button1.ImageColor3 = Color3.new(1, 0, 0)
            print("No!")
            
            
            
            
end
    end

enable.OnServerEvent:Connect(enableButton)```
teal horizon
#

Haii everyone

teal horizon
#

ok

glass otterBOT
#

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

teal horizon
#

@rocky egret

rocky egret
#

Hey, you've got a lot of code and it's not entirely clear to me what your desired outcome is. What order you are triggering things etc.

I would suggest adding prints throughout the code that isn't working to nail down which exact line is not working as expected.

teal horizon
#

u know what i want

rocky egret
#

i made a upgrade system where if you reach 100 value you go to another level manually but it aint working with the autoclicker
only if i click manually
my whole script broke
now it aint changing size
now im not gaining anything

sounds like you have a ton of different systems all trying to change + read luckyBlocks value? But also sounds like onEnd() didn't trigger because you mentioned size didn't change?

Idk there is just too much going on for me to understand over discord, you'll have to dial in to a single problem and find a specific error, then I might be able to help

teal horizon
#

but thats in the function where i click tho

#

so if i dont click it wont work

teal horizon
#

😠

teal horizon
#

My game is never gonna get done