Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make the vent stay in its unanchored state when the player stops touching it?

So, how do I make the vent stay in this unanchored state when the player stops touching it? The vent is supposed to drop when the player touches it but instead it just drops a little but its in mid-air when the player stops touching it. How do I achieve something like this?

Script: LocalScript

Location: StarterPlayerScripts

Code:

local Vent = game.Workspace.Lobby.Floor.Vent

Vent.Touched:Connect(function(Drop)
if Drop.Parent:FindFirstChild("Humanoid") then
Vent.Anchored = false
Vent.CanCollide = false
end
end)

Thanks for reading!

2 comments

0

I don't get it. I just tested out the exact same code and it works fine, it doesn't stop mid-air

0

it does for me though, what I mean is to make the vent stay in its unanchored and can collide false state when the player stops touching it

2 answers

✓ Accepted answer

I think i have an idea on how to make it not go back to it's state when you stop touching it.

local Vent = game.Workspace.Lobby.Floor.Vent
local UnanchoredState = false
local CantCollide = false

Vent.Touched:Connect(function(Drop)
	if Drop.Parent:FindFirstChild("Humanoid") then
		Vent.Anchored = UnanchoredState
		Vent.CanCollide = CantCollide
		Vent.TouchEnded:Connect(function(StayDropped)
			Vent.Anchored = UnanchoredState
			Vent.CanCollide = CantCollide
		end)
	end
end)

Hope this helps! Leave a comment if there is something wrong and i will try to fix it.

8 comments

0

still does the same thing...

0

why does can collide work but anchored does not and also what does the stay dropped thing do in line 9?

0

im going to be honest i think i was going to do something with the StayDropped but probably forgot and I don't know what i was meant to do with that anymore...

0

im going to be honest i think i was going to do something with the StayDropped but probably forgot and I don't know what i was meant to do with that anymore...

0

so does it say anchored but you can still walk through?

0

yes its anchored but i can walk through it and its can collide false

0

well i just replaced my script with mouse click detector thing instead of touched and made it so that when you click it, it gets more transparent, when its fully transparent its can collide false

0

I think that is easier tbh.

  1. stopping mid-air could be a network ownership swap Make sure that either the client or the server has network ownership over the block so it doesn't swap. You can use this with Part:SetNetworkOwner() Leaving the parameters empty will make it the server, if you put the player inside the parameter then it will be controlled by the client.

  2. if 1 wasn't what you were looking for then this may: It also sounds like you want the touch event to reverse? Either use a timer or use TouchEnded ex:

Vent.TouchEnded:Connect(function(Drop)
	-- code to re-anchor and enable cancollide on the vent.
end)

2 comments

0

I mean is there a way when the player stops touching the vent, how do you make it so that when the player no longer touches it, the vent will not change back to its original state after the player no longer touches it?

0

BTW The script is a local script and its located inside starter player scripts.

This discussion is preserved as it was. New answers, comments, and votes are closed.