Elevator doesn't goes up

So I scripted a elevator for lobby that should go up or down (if already up, goes down. if already down, goes up) when touched. It goes down but if I touch it again it doesn’t go up.
Script I used:

game.Players.PlayerAdded:Connect(function()
	b = game.Workspace.Lobby.LobbyElev.elevator.Position
	local be = game.Workspace.Lobby.LobbyElev.elevator
	debouncee = false

	function fall(hit)
		if hit.Parent:findFirstChild("Humanoid") and debouncee == false then
			if b.y == 0 then
				pos = {Position = Vector3.new(b.x, b.y-18.25, b.z)}
			elseif b.y == -18.25 then
				pos = {Position = Vector3.new(b.x, 0, b.z)}
			end
			debouncee = true
			wait(.1)
			local TweenService = game:GetService("TweenService")
			coil = game.Workspace.Lobby.LobbyElev.elevator
			tweenInfo = TweenInfo.new(
				5, 
				Enum.EasingStyle.Sine,
				Enum.EasingDirection.InOut, 
				0, 
				false, 
				0 
			)
			local tween = TweenService:Create(coil, tweenInfo, pos)
			tween:Play()
			wait(5)
			debouncee = false
		end
	end

	game.Workspace.Lobby.LobbyElev.elevator.Touched:connect(fall)
end)

Thanks.

Any errors? (extra characters lol)

Maybe try removing the playerAdded part

b = game.Workspace.Lobby.LobbyElev.elevator.Position
	local be = game.Workspace.Lobby.LobbyElev.elevator
	debouncee = false

	function fall(hit)
		if hit.Parent:findFirstChild("Humanoid") and debouncee == false then
			if b.y == 0 then
				pos = {Position = Vector3.new(b.x, b.y-18.25, b.z)}
			elseif b.y == -18.25 then
				pos = {Position = Vector3.new(b.x, 0, b.z)}
			end
			debouncee = true
			wait(.1)
			local TweenService = game:GetService("TweenService")
			coil = game.Workspace.Lobby.LobbyElev.elevator
			tweenInfo = TweenInfo.new(
				5, 
				Enum.EasingStyle.Sine,
				Enum.EasingDirection.InOut, 
				0, 
				false, 
				0 
			)
			local tween = TweenService:Create(coil, tweenInfo, pos)
			tween:Play()
			wait(5)
			debouncee = false
		end
	end

	game.Workspace.Lobby.LobbyElev.elevator.Touched:connect(fall)

I’d recommend u to use constraints for this, I heard that the prismatic constraint can simulate this behavior. Tell me if am wrong

I think it’s just because you should put a local function. Just put local in front of function, it should work, I guess. I am presently on my phone, I can’t presently verify myself. :S

By the way, I don’t know why you first put a player added “detection” if the script is for a server elevator. If it’s a server script to move object for each player, I would recommend you to use a local script for each player.

I just got an idea, put a print() (The printed string got to be something significative, at least.)at the beginning of the function fall() to just verify if the function itself is triggered twice or just once, and you can then make more severals tries after in the if statement. If it doesn’t print something, then you know where is the problem. It’s a trick I frequently use

I may try that later, but I dont know how to do that ¯_(ツ)_/¯

image
Twice.

If the print() is working, then just go further in the script and check if all of the if statements are working like it’s use to, one by one or each with a different message like “The elevator is exactly at Y axis high” , it’s not always the first part of the script that is not working.

(Note: Sometimes, if you are trying to do if statement with exact parts position properties, it might happen that what you think is 15 studs high are 14.995 or 16.002 according to the game eye. You should probably add or subtract a the amount of floor the elevator will move from a local value. It will be then possible to tell the elevator where to go. (Maybe according to if statement, to tell the script what should be the high where to stop for each floor or from a mathematical function that will automatically tell the script where to stop the elevator for each floor depending on the floor local value))

I got to have some more explanation on what’s going on to know what to do to help you.

Is it supposed to be a local or server side elevator? Since it’s a lobby, I would have done it server side, but it’s looking like you are trying to do it local.

By the way, for which reason are you using HttpsService?

A couple things:

You should be not use wait(5) for the pause , but do so using the Tween Completed event. I think you can replace the wait(5) with this, to make sure the debounce isn’t reset until the elevator is completely down:

 tween.Completed:Wait()

besides this, I wouldn’t tween this elevator platform except perhaps use a AlignPosition constraint with an attachment on the cframed/tweened platform target, that’s invisible and CanCollide=false, Anchor=true, and then a platform part that followed the position of the cframed part with an attachment from bottom of the real platform to the top of the platform target. This would work better I think with players on the platform, as the system will see its using physics instead of cframes.
You should just need to set the attachment setting on each part on the AlignPosition contraint settings - attachment0 and attachment1… I can’t recall offhand which you should set, but just try the attachment you setup on the platform as attachment0 first, and see how that works out (attachment0 is connected to the part that the physics should affect (by default), with attachment1 not being affected)

1 Like