Trying to make an Iron Man Mask Effect with a helmet

  1. What do you want to achieve? Keep it simple and clear!
    I want to try and achieve like the iron man mask effect with this helmet if you press “E” on your keyboard; it’s meant to go up; when you press it again it goes down.
  2. What is the issue? Include screenshots / videos if possible!
    The issue is whenever I move the glass screen goes in a different direction and doesn’t go up or down; like it’s meant to do.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? - I’ve tried parenting the helmet in the players head it does the same effect; I’ve tried searching around on the hub but couldn’t find anything to help.
local player = script.Parent.Parent.Parent.Character
local isGlassScreenModified = false
local isHelmetOn = false

local function tweenGlassScreen(endSize, endPosition)
	local TweenService = game:GetService("TweenService")
	local glassScreen = player.Helmet.GlassScreen

	local initialPosition = glassScreen.Position

	local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
	local tween = TweenService:Create(glassScreen, tweenInfo, { Size = endSize, Position = endPosition })

	glassScreen.Position = initialPosition

	player.Humanoid:LoadAnimation(script.HelmetAttract):Play()

	wait(0.3)
	glassScreen.ButtonSFX:Play()
	wait(0.2)
	tween:Play()
	glassScreen.MachineSFX:Play()

	wait(0.7)
	glassScreen.MachineSFX:Stop()


	isGlassScreenModified = not isGlassScreenModified
end

local function toggleHelmet()
	local endSize, endPosition

	if isHelmetOn then
		endSize = Vector3.new(1.481, 0.737, 0.839)
		endPosition = player.Helmet.GlassScreen.Position - Vector3.new(0.12, 0.26, -0.2173)
	else
		endSize = Vector3.new(1.481, 0.111, 0.839)
		endPosition = player.Helmet.GlassScreen.Position + Vector3.new(0.12, 0.26, -0.2173)
	end

	tweenGlassScreen(endSize, endPosition)
	isHelmetOn = not isHelmetOn
	print(isHelmetOn and "Helmet turned on" or "Helmet turned off")
end

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.E then
		toggleHelmet()
	end
end)

Video Link
As shown in the video it goes up (slight position issue) and then it goes down to the default position but once I move my character like in a circle or something it just offsets idk why.

1 Like

Any ideas, on how to solve it?

Because you’re only tweening the Position, not the Orientation. You’ll need to do both.

1 Like

I just tested it right now; I tweened the orientation but it still does the same thing when I move the glass flies off.

There doesn’t appear to be anything inherently wrong with the script. However, it’s important to note that the script assumes the existence of certain objects and properties in the game hierarchy. Make sure that the script is placed in the correct location and that the necessary objects and properties are present. (Make sure where you place it, some people place the wrong script in the character folder and some place the starter character scripts in the tool itself. :wink:)

Additionally, it’s always a good idea to include error handling in your scripts. You can use calls to catch any potential errors and handle them gracefully. :smile:

1 Like

Yep! They’re all placed in the right place I do make an error handler incase some issues happen but the actual issue comes from the actual model lemme try and explain what the actual issue is; it’s nothing to do with the scripting I believe but lemme try and explain.

image
This is how it looks like in explorer if your curious; but I feel like it’s something to do with the welding or it being in the wrong place like the glass screen; like if you stand still it does as intended but if you move around the glass screen goes elsewhere could this be a collision/welding issue?