Parts disappear after playtesting

Whenever I test my game, parts from the workspace disappear.

Script:
appear = game.Workspace

    function onClick()

    game.workspace.sphere1.Transparency=0.8

    wait(0.1)

    game.workspace.sphere1.Transparency=1

    wait(0.1)

    game.workspace.sphere2.Transparency=0.8

    wait(0.1)

    game.workspace.sphere2.Transparency=1

    wait(0.1)

    game.workspace.sphere3.Transparency=0.8

    wait(0.1)

    game.workspace.sphere3.Transparency=1

    end

    script.Parent.ClickDetector.MouseClick:Connect(onClick)

Did I mention I’m new to scripting?
P.S I changed the parts into transparency into 1 in studio.

Anyways, here’s what happening:

image

After playtesting:

image

Any help?

1 Like

The code you have here shouldn’t be deleting them, so I would consider checking the properties of each sphere to make sure that they are anchored and collisions are enabled. If you have any other scripts running, you might want to look over them to confirm that they aren’t altering the spheres.

1 Like

Found out that I should have used locals. Thanks for the help!

This isn’t the issue with your code, but please don’t do this. You can use TweenService for smoother and less ugly (code-wise) results. Also, game.workspace is deprecated. You can do game:GetService("Workspace") (get any service based on its classname), game.Workspace (use the property of game that only exists for workspace), or workspace (a global that refers to the workspace).

1 Like

Sorry, I’m really new to scripting (Hence the Modeler tag beside my username). I appreciate the tip!