Script Not Changing Value

Hello Developers!

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)
----

Please help me fix this!

1 Like

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

1 Like

It’s still doing the same thing where it only is moving the Left Arm and not switching to the Right. Value is also staying the same too.

1 Like

Is something being printed when the function is called?

1 Like

Nothing is being printed in the Output {char 2.0}

Your GPE variable is likely set to true. Try removing

if GPE then return end

… to check and see if it works without it.

Same result is happening. Only moving the Left Arm

1 Like

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 :sob: 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?

Can you show me your current code that moves the arms?

function ClimbModule:GuideArm(Character,Target)
	-- Check {For Characters PrimaryPart} --
	if Character.PrimaryPart then
		
		-- Variables {Characters New Shoulders} --
		local NewLeftShoulder = Character.LeftUpperArm:FindFirstChild('NewLeftShoulder')
		local NewRightShoulder = Character.RightUpperArm:FindFirstChild('NewRightShoulder')
		----

		-- Disable {Current Shoulders} --
		Character.LeftUpperArm['LeftShoulder'].Enabled = false
		Character.RightUpperArm['RightShoulder'].Enabled = false
		-- Enable {New Shoulders} --
		NewLeftShoulder.Enabled = true
		NewRightShoulder.Enabled = true
		----
		
		-- Check {For CurrentArms Value} --
		if ValueFolder.CurrentArm.Value == 'Left' then
			GuideArmMovement(NewRightShoulder,Target,CFrame.new(0.89,0.5,-0.15))
		elseif ValueFolder.CurrentArm.Value == 'Right' then
			GuideArmMovement(NewLeftShoulder,Target,CFrame.new(-0.89,0.5,-0.15))
		end
		----
	end
end
----

Sorry, can I also have the updated code that calls this function?

It’s the same thing as this one

-- 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)
----

Are you sure this isn’t already moving the arms one by one ? Do you have a video example?

It’s moving both the arms at the same time let me clip it for you real quick

Watch 2024-04-18 18-59-36 | Streamable {char 2.0}

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

It does the same thing. It uses both arms instead of just one at a time