I want the door to remain open if the player has opened it and is inside the green zone. I attempted to use Worldroot:GetPartsinPart(), but that method requires me to switch to a localscript and tween service doesn’t work there. Any help would be greatly appreciated
local tweenService = game:GetService("TweenService")
local frame = script.Parent
local model = frame.Parent
local clickDetector = script.Parent:WaitForChild("ClickDetector")
local openSound = frame:WaitForChild("DoorOpen")
local frameClose = model:WaitForChild("DoorFrameClose")
local frameOpen = model:WaitForChild("DoorFrameOpen")
local debounce = true
local opened = false
local function doorOpen()
if debounce == true then
debounce = false
if opened == false then
opened = true
openSound:Play()
tweenService:Create(frame,TweenInfo.new(2.5),{CFrame = frameOpen.CFrame}):Play()
task.wait(2)
tweenService:Create(frame,TweenInfo.new(1),{CFrame = frameClose.CFrame}):Play()
opened = false
end
wait(1)
debounce = true
end
end
clickDetector.MouseClick:Connect(doorOpen)
You don’t need GetPartsInPart for this to work, just write a Point-in-Box function where the points are the centers of the players’ primary parts. You could even ask Roblox’s Documentation Assistant to write one up for you!
While there are some points found within the box, you just task.wait(x) it out until the next check. If there are no points found then that’s when you move on to closing.
game.Players.PlayerAdded:Connect(function(plr)
local character = plr.Character or plr.Character.Added:Wait()
local humanoid = character:WaitForChild("Humanoid")
end)
Should the script to check the player’s position be placed inside game.Players.PlayerAdded:Connect? If so, how can I ensure that the function runs again to check the position