If loops not behaving properly

I am trying to make a script in a tool where you can transform and untransform from a certain character, however the cooldown will not work whatsoever, and the if transform loop always runs if transform.Value == false then even when transform is equal to true, and yes i have checked with a print

cooldown1 = false
transform = script.Parent.Transformed -- BoolValue

script.Parent.Activated:Connect(function()
	
	local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
	
	if cooldown1 == false then
		cooldown1 = true

		if transform.Value == false then

			transform.Value = true
			print(transform.Value)

			char = script.Parent.Parent
			char.Archivable = true

			char.Parent = game.ServerStorage
			backupChar = char

			char.HumanoidRootPart.Position += Vector3.new(0, 20, 0)

			morph = game.ServerStorage.BuddhaModel:Clone()

			char.Shirt.Parent = morph
			char.Pants.Parent = morph

			morph.Name = char.Name

			morph:SetPrimaryPartCFrame(char.PrimaryPart.CFrame)

			player.Character = morph

			morph.Parent = game.Workspace

		elseif transform.Value == true then

			player:LoadCharacter()

			transform.Value = false

		end

		wait(3)
		cooldown1 = false

	end
end)

The if statements work for me, maybe something regarding the character is affecting it.

(The script under is working forme)

local cooldown1 = false
local transform = script.Parent.Transformed -- BoolValue

script.Parent.Activated:Connect(function()
	local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)

	if cooldown1 == false then
		cooldown1 = true
		print("on cooldown")

		if transform.Value == false then
			transform.Value = true
			print(transform.Value)
			
			-- your script

		elseif transform.Value == true then
			transform.Value = false
			print(transform.Value)
			
			-- your script
			
		end

		wait(3)
		cooldown1 = false
		print("cooldown ended")

	end
end)

I think I might have found the problem. When you equip a tool it gets added to your character, and then when you move the character to ServerStorage you cannot use that tool anymore, because you are no longer that character with that tool. Meaning you can’t use the tool anymore after you morph.

1 Like

that’s fine, i only want to be able to morph while holding the tool

oh wait i misunderstood, sorry i understand now lol

My wording is probably a bit off (English isn’t my first language). That aside, you probably have to move the tool to the morph, if you want the player to be able to morph back using the same tool.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.