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

Why does my script set var to true whenever it is touched?

Asked by
kyrumV2 -5
4 years ago
Edited 4 years ago
var = true
flag = script.Parent
script.Parent.Touched:Connect(function(hit)
    print(var)
    wait(1)
    if var == true then
        if hit.Parent ~= workspace and hit.Name ~= "Dirt" and hit.Parent.Name ~= "Model" and hit.Parent.Humanoid then
            var = false
            flag.Position = Vector3.new(0,0,0) 
            print("move flag")
            clone = flag:Clone()
            print("cloned")
            clone.Parent = workspace
            local hrp = hit.Parent.HumanoidRootPart
            clone.CFrame = hrp.CFrame * CFrame.new(0,0,2)
            local weld = Instance.new("Weld")
            weld.Part0 = hrp
            weld.Part1 = clone
            weld.C0 = hrp.CFrame:Inverse()
            weld.C1 = clone.CFrame:Inverse()
            clone.Anchored = false
            weld.Parent = clone
            repeat wait(1)
            print(var)
            until false

            hit.Parent.Humanoid.Died:Connect(function()
                var = true
                clone:Destroy()
                flag.Position = Vector3.new(-60.004, 84.82, -127.496)
            end)
        end
    end
end)

If I touch another player it sets var to true for a second and then everything breaks.

0
ok it did not work but now i cahnged it so that it does not clone so it works : () kyrumV2 -5 — 4y

Answer this question