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

when i click a button to disable a boolvalue i get an error saying attempt to call a nil value?

Asked by 1 year ago
Edited by Leamir 1 year ago

How would i fix it these are the scripts for enable and disable i tried it with value = true and value=true

(enable ---Model By: Midnight Productions

location = script.Parent.Parent.Parent
regen = script.Parent.Parent
save = regen:clone()

script.Parent.ClickDetector.MouseClick:connect(onClicked)

function onClicked()
    script.Parent.Parent.IsOutOfOrder.Value=false 
end )

( Disable ---Model By: Midnight Productions

location = script.Parent.Parent.Parent
regen = script.Parent.Parent
save = regen:clone()

script.Parent.ClickDetector.MouseClick:connect(onClicked)

function onClicked()
    script.Parent.Parent.IsOutOfOrder.Value=true 

end  )
0
Edit: Add codeblocks Leamir 3138 — 1y
0
Can I ask which line is that error on? Leamir 3138 — 1y
0
It wont say which line cbeebiespoo -5 — 1y
0
the whole error says 15:28:50.511 attempt to call a nil value - Server cbeebiespoo -5 — 1y

1 answer

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
1 year ago
Edited 1 year ago

Hello, cbeebiespoo!

Edit:

Apparently you are using each code on one part, so you dont want the click to toggle the value.

You just need to move the :Connect to under the function

Disable:

location = script.Parent.Parent.Parent
regen = script.Parent.Parent
save = regen:clone()

function onClicked()
    script.Parent.Parent.IsOutOfOrder.Value= true
end )

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

Enable:

location = script.Parent.Parent.Parent
regen = script.Parent.Parent
save = regen:clone()

function onClicked()
    script.Parent.Parent.IsOutOfOrder.Value= false
end )

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

Old answer:

I found 3 problems in your code:

  1. You are calling the :Connect before defining the function, this can be easily fixed by moving the :Connect line to under the function definition

  2. This doesn't really breaks your code, but may in the future. The :connect has been deprecated, it is recommended to use :Connect for new code.

  3. The 2 scripts are reverting each other actions. You should use just one script to change the value, like so:

location = script.Parent.Parent.Parent
regen = script.Parent.Parent
save = regen:clone()

function onClicked()
    script.Parent.Parent.IsOutOfOrder.Value= not script.Parent.Parent.IsOutOfOrder.Value --This inverts the value from the BoolValue
end )

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

If this solves your ploblem, please mark this answer as the "Accepted Answer"

0
There both on different ones cbeebiespoo -5 — 1y
0
? can you explain better what you are trying to say? I dont understand Leamir 3138 — 1y
0
they were both in different buttons cbeebiespoo -5 — 1y
0
should i change the not to false / true cbeebiespoo -5 — 1y
View all comments (6 more)
0
Check the edit, I belive that will work Leamir 3138 — 1y
0
? cbeebiespoo -5 — 1y
0
how do i also mark this as the accepted answer cbeebiespoo -5 — 1y
0
Under the answer and its comments, theres a button "Accept Answer" or something like that Leamir 3138 — 1y
0
it didnt work :( cbeebiespoo -5 — 1y
0
il come back later and try cbeebiespoo -5 — 1y
Ad

Answer this question