i need help this is the script:
script.Parent.Parent.Activated:connect(function()
local a = game.Workspace.LogRideToggled.Value
if a == true then
a = false
script.Parent.Click:Play()
end
if a == false then
a = true
script.Parent.Click:Play()
end
end)
this is the hirachy:
https://i.stack.imgur.com/ZmrmG.jpg
but NOTHING happens, no errors either, except for the click sound playing i seriously need help
The problem is is that after you do
a == true, you setatofalse, whicha == falsethen matches after.You can solve this with an
if then else endstatement, like so:However, this will only change the local value of
a, which means that it will not save the change. To fix this, we need to assign thegame.Workspace.LogRideToggleds value ofValuedirectly, which we can do like:Although it's bad practice to repeatedly index this like this, so we can store
game.Workspace.LogRideToggledin a local variable. You can read up on why this works but storingvaluedoesn't hereAlso, the
== trueis redundant, as Lua expects atruthyorfalseyvalue as the condition, all== truedoes in this case is givetrueorfalseif it's true of false.Yet we can clean this up a bit more, as we use
script.Parent.Click:Play()in both cases, and we can replacelogRideToggled.Value =with a logical not, like so.But if you only want to toggle this value, not do anything special for either case, we can remove that entire conditional, leaving:
Hope this has helped!