I’m working on a Arm Tracker Game & I’ve ran into a problem. When Clicking it should automatically change the CurrentArm.Value from either Left To Right or vice versa, but its not doing that at all.
Code
local function LoopCurrentArm()
-- Check {CurrentArms Value} --
if ValueFolder.CurrentArm.Value == 'Left' then
ValueFolder.CurrentArm.Value = 'Right'
end
----
-- Check {CurrentArms Value} --
if ValueFolder.CurrentArm.Value == 'Right' then
ValueFolder.CurrentArm.Value = 'Left'
end
----
-- Debug {For Fixing} --
ValueFolder.CurrentArm.Changed:Connect(function()
print(ValueFolder.CurrentArm.Value)
end)
end
----
-- UserInputService {InputBegining} --
UserInputService.InputBegan:Connect(function(InputBind,GPE)
if GPE then return end
-- Check {UserInputStating {Just The Mouse}} --
if InputBind.UserInputType == Enum.UserInputType.MouseButton1 then
ClimbModule:GuideArm(game.Players.anxlr.Character,workspace.Part.Position)
-- Call Function {Change CurrentArm Value} --
LoopCurrentArm()
end
end)
----
Currently, it will always set the CurrentArm.Value to “Right” because the first if statement sets it to “Right” and then immediately after, the second if statement sets it to “Left”.
To fix this, you need to ensure that only one of the if statements is executed each time the function is called. You can achieve this by using an if-else structure or by using a single if statement with an else clause.
local function LoopCurrentArm()
-- Check the current value of CurrentArm.Value
if ValueFolder.CurrentArm.Value == 'Left' then
-- If it's "Left", change it to "Right"
ValueFolder.CurrentArm.Value = 'Right'
else
-- If it's not "Left" (i.e., it's "Right"), change it to "Left"
ValueFolder.CurrentArm.Value = 'Left'
end
-- Debugging
print(ValueFolder.CurrentArm.Value)
end
I suspect the issue is now something with this function here:
-- UserInputService {InputBegining} --
UserInputService.InputBegan:Connect(function(InputBind,GPE)
if GPE then return end
-- Check {UserInputStating {Just The Mouse}} --
if InputBind.UserInputType == Enum.UserInputType.MouseButton1 then
ClimbModule:GuideArm(game.Players.anxlr.Character,workspace.Part.Position)
-- Call Function {Change CurrentArm Value} --
LoopCurrentArm()
end
end)
----
… but I can’t determine that without additional debuggers. Can you try printing after each line and see where it stops printing?
Okay so I made a mistake earlier and put the function inside of the function and didn’t notice at all. It moves both arms but I need to move it one at a time. How can I achieve that?
-- UserInputService {InputBegining} --
UserInputService.InputBegan:Connect(function(InputBind,GPE)
if GPE then return end
-- Check {UserInputStating {Just The Mouse}} --
if InputBind.UserInputType == Enum.UserInputType.MouseButton1 then
ClimbModule:GuideArm(game.Players.anxlr.Character,workspace.Part.Position)
-- Call Function {Change CurrentArm Value} --
LoopCurrentArm()
end
end)
----
If this is left it will switch to right. Then it will hit the next lines being right, it will get turned back to left. Can get around this with an elseif …
if ValueFolder.CurrentArm.Value == 'Left' then
ValueFolder.CurrentArm.Value = 'Right'
elseif ValueFolder.CurrentArm.Value == 'Right' then
ValueFolder.CurrentArm.Value = 'Left'
end