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 2 years ago
Edited by Leamir 2 years 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

1location = script.Parent.Parent.Parent
2regen = script.Parent.Parent
3save = regen:clone()
4 
5script.Parent.ClickDetector.MouseClick:connect(onClicked)
6 
7function onClicked()
8    script.Parent.Parent.IsOutOfOrder.Value=false
9end )

( Disable ---Model By: Midnight Productions

01location = script.Parent.Parent.Parent
02regen = script.Parent.Parent
03save = regen:clone()
04 
05script.Parent.ClickDetector.MouseClick:connect(onClicked)
06 
07function onClicked()
08    script.Parent.Parent.IsOutOfOrder.Value=true
09 
10end  )
0
Edit: Add codeblocks Leamir 3138 — 2y
0
Can I ask which line is that error on? Leamir 3138 — 2y
0
It wont say which line cbeebiespoo -5 — 2y
0
the whole error says 15:28:50.511 attempt to call a nil value - Server cbeebiespoo -5 — 2y

1 answer

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
2 years ago
Edited 2 years 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:

1location = script.Parent.Parent.Parent
2regen = script.Parent.Parent
3save = regen:clone()
4 
5function onClicked()
6    script.Parent.Parent.IsOutOfOrder.Value= true
7end )
8 
9script.Parent.ClickDetector.MouseClick:Connect(onClicked)

Enable:

1location = script.Parent.Parent.Parent
2regen = script.Parent.Parent
3save = regen:clone()
4 
5function onClicked()
6    script.Parent.Parent.IsOutOfOrder.Value= false
7end )
8 
9script.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:

1location = script.Parent.Parent.Parent
2regen = script.Parent.Parent
3save = regen:clone()
4 
5function onClicked()
6    script.Parent.Parent.IsOutOfOrder.Value= not script.Parent.Parent.IsOutOfOrder.Value --This inverts the value from the BoolValue
7end )
8 
9script.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 — 2y
0
? can you explain better what you are trying to say? I dont understand Leamir 3138 — 2y
0
they were both in different buttons cbeebiespoo -5 — 2y
0
should i change the not to false / true cbeebiespoo -5 — 2y
View all comments (6 more)
0
Check the edit, I belive that will work Leamir 3138 — 2y
0
? cbeebiespoo -5 — 2y
0
how do i also mark this as the accepted answer cbeebiespoo -5 — 2y
0
Under the answer and its comments, theres a button "Accept Answer" or something like that Leamir 3138 — 2y
0
it didnt work :( cbeebiespoo -5 — 2y
0
il come back later and try cbeebiespoo -5 — 2y
Ad

Answer this question