Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why wont my script turn off when I change the variable?

So im making a script for a game and im new so i dont know this stuff but when i try to turn off my script instead of turning off it prints the turn off message but does not turn off can someone tell me why (@T3_MasterGamer help pls)

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
 local on = false
script.Parent.MouseButton1Click:Connect(function()
	if on == false then
		print("turning on")
		repeat 
			wait(1)
			 on = true
			local part2 = Instance.new("Part", workspace)
			part2.CanCollide = false
			part2.Anchored = true
			part2:PivotTo(character:WaitForChild("Head"):GetPivot() * CFrame.new(0, 0, 10))
			part2.Name = "Part1"

			character:WaitForChild("Humanoid"):MoveTo(part2.Position, part2)
			
		until on == false
	else 
		on = false
		print("Turning off :(")
		game.Workspace:WaitForChild("Part2"):Destroy()
		script.Parent:Destroy()
	end
end)

3 comments

0

what is your goal in this script?

0

anti afk

0

sorry i can't help i'm too confused :(

1 answer

If it prints the message but doesn't do anything afterwards, the only answer is your WaitForChild call is infinitely yielding (it should print a warning in the console if stuck for too long, around 2 to 3 seconds). This means that the instance never appeared in the location you specified - check if you wrote the correct location and instance name.

This discussion is preserved as it was. New answers, comments, and votes are closed.