lua - im having troubles getting my toggle script working in roblox -
i need script:
script.parent.parent.activated:connect(function() local = game.workspace.logridetoggled.value if == true = false script.parent.click:play() end if == false = true script.parent.click:play() end end)
this hirachy:
but nothing happens, no errors either, except click sound playing need help
the problem is after a == true
, set a
false
, a == false
matches after.
you can solve if else end
statement, so:
script.parent.parent.activated:connect(function() local = game.workspace.logridetoggled.value if == true = false script.parent.click:play() else = true script.parent.click:play() end end)
however, change local value of a
, means not save change. fix this, need assign game.workspace.logridetoggled
s value of value
directly, can like:
script.parent.parent.activated:connect(function() if game.workspace.logridetoggled.value == true game.workspace.logridetoggled.value = false script.parent.click:play() else game.workspace.logridetoggled.value = true script.parent.click:play() end end)
although it's bad practice repeatedly index this, can store game.workspace.logridetoggled
in local variable. can read on why works storing value
doesn't here
script.parent.parent.activated:connect(function() local logridetoggled = game.workspace.logridetoggled if logridetoggled.value == true logridetoggled.value = false script.parent.click:play() else logridetoggled.value = true script.parent.click:play() end end)
also, == true
redundant, lua expects truthy
or falsey
value condition, == true
in case give true
or false
if it's true of false.
script.parent.parent.activated:connect(function() local logridetoggled = game.workspace.logridetoggled if logridetoggled.value logridetoggled.value = false script.parent.click:play() else logridetoggled.value = true script.parent.click:play() end end)
yet can clean bit more, use script.parent.click:play()
in both cases, , can replace logridetoggled.value =
logical not, so.
script.parent.parent.activated:connect(function() local logridetoggled = game.workspace.logridetoggled if logridetoggled.value -- todo if truthy else -- todo if falsey end logridetoggled.value = not logridetoggled.value script.parent.click:play() end)
but if want toggle value, not special either case, can remove entire conditional, leaving:
script.parent.parent.activated:connect(function() local logridetoggled = game.workspace.logridetoggled logridetoggled.value = not logridetoggled.value script.parent.click:play() end)
hope has helped!
Comments
Post a Comment