Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
2mania 14
2 years ago

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)
0
what is your goal in this script? T3_MasterGamer 2189 — 2y
0
anti afk 2mania 14 — 2y
0
sorry i can't help i'm too confused :( T3_MasterGamer 2189 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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.

Ad

Answer this question