Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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  )

4 comments

0

Edit: Add codeblocks

0

Can I ask which line is that error on?

0

It wont say which line

0

the whole error says 15:28:50.511 attempt to call a nil value - Server

1 answer

✓ Accepted answer

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"

10 comments

0

There both on different ones

0

? can you explain better what you are trying to say? I dont understand

0

they were both in different buttons

0

should i change the not to false / true

0

Check the edit, I belive that will work

0

?

0

how do i also mark this as the accepted answer

0

Under the answer and its comments, theres a button "Accept Answer" or something like that

0

it didnt work :(

0

il come back later and try

This discussion is preserved as it was. New answers, comments, and votes are closed.