I need help with this script

why doesn’t this work??
– the tween

 
local tweenInfo = TweenInfo.new(
	2, -- Time
	Enum.EasingStyle.Linear, -- EasingStyle
	Enum.EasingDirection.Out, -- EasingDirection
	-1, -- RepeatCount (when less than zero the tween will loop indefinitely)
	true, -- Reverses (tween will reverse once reaching it's goal)
	0 -- DelayTime
)```
-- locals 

```local Part = script.Parent.Parent.elevatorpart -- the elevator 
local tween1 = TweenService:Create(Part, tweenInfo, {Position = Vector3.new(114.377, 22.635, -16.449)}) -- the position for the elevator
local button = script.Parent -- the button
local EMbutton = script.Parent.Parent.emergencybutton -- the emergency button```

-- the scripts
```button.ClickDetector.MouseClick:Connect(function() -- click detector
	tween1:Play() -- the tween plays
	if EMbutton.ClickDetector.MouseClick then -- if the player clicks the emergency button then the next function fires.
		if Part.Position == (114.377, 22.635, -16.449) then -- the elevators starting position
			tween1:Pause() -- the tween pauses
			wait (0)
			tween1:Play()
			if Part.Position == (114.377, 1.815, -16.449) then -- if the part is at the start then the tween will stop
				tween1:Cancel()
			end
		wait(1)	
		end
	wait(1)	
	end
end)```

give me a min and i will edit it so you can read it better

Can you explain what is not working? Are you getting any errors in the output?

Also, a better section for this would be in #help-and-feedback:code-review.

EDIT: Can we get a screenshot of any errors in the output, if there are any, so we can pinpoint the problem @Yo2uber99?

the whole script wont work
button.ClickDetector.MouseClick:Connect(function()
tween1:Play()
if EMbutton.ClickDetector.MouseClick then
if Part.Position == (114.377, 22.635, -16.449) then
tween1:Pause()
wait (0)
tween1:Play()
if Part.Position == (114.377, 1.815, -16.449) then
tween1:Cancel()
end
wait(1)
end
wait(1)
end
end)

First, do you get any errors in the output? If yes, could you send the image(s)?

Second, please format your code properly by putting ``` at the beginning and end of your code. It’s easier for us to read.

the button doesn’t work
button.ClickDetector.MouseClick:Connect(function()

Make sure that:

  • The script is inside of the elevator button
  • There is a ClickDetector located directly inside of the elevator button

If the above is all correct, I’m not sure what else could be the issue.

Can I have an image of the output when you run the code? Are there any errors? I would be able to pinpoint the problem much better if you were to provide me this.

1 Like