Here's the basic idea of the toggle:
Using think, if the player has pressed E, but has not pressed E the last frame, a function activates, making a boolean true.
In the same function, if the above conditions are not met, we then test if E was pressed last frame, but not this one. This makes the boolean false.
hook.Add("Think", "someUniqueName", function()
if LocalPlayer():KeyDown(IN_USE) and !LocalPlayer():KeyDownLast(IN_USE) then
somebool = true
elseif LocalPlayer():KeyDownLast(IN_USE) and !LocalPlayer():KeyDown(IN_USE) then
somebool = false
end
end )
I tried this same concept and got no results. Since there are plenty of mishaps I could have made, this is the full snippet. It's for a revive mod.
https://pastebin.com/raw/PSYFr5W0
If anybody could help, that would be legitness. Also, its probabaly a stupid and easy answer, and I already regret the huge coin bounty, but take it anyways. I have.... alot of coins.
Think less about the previous frame and more about the state of your variables.
For instance, you might store this state of button-holding on the player as LocalPlayer().toggleVar and LocalPlayer().holdingUse
hook.Add("Think","wowItToggles",function()
local useDown = LocalPlayer():KeyDown(IN_USE)
if useDown != LocalPlayer().holdingUse then
--we know the player has either just started holding it, or just let go
--we want toggleVar to toggle whenever the button has been let go
if useDown == false then LocalPlayer().toggleVar = !LocalPlayer().toggleVar end
--now store the button state so that next 'Think' all the above logic still works:
LocalPlayer().holdingUse = useDown
end
end)
Thanks for the genius response. I do think that "not nil" is true, so this should work, otherwise I'll just have to init as false. Can't believe I didn't think of this... 😩
Sorry, you need to Log In to post a reply to this thread.