So yesterday I made to post on help in this door I was making, two times I was helped and it worked perfectly. Now I think I’m in the last stretch of completing this thing,
How the door works:
So when a player enters a 10-stud radius within the door it’ll open 180 degrees, and when the leave it the door closes, it works fine except for the part that when you get in the 10-stud radius it goes absolutely berserk:
-note roblox won’t frigging let me upload it here so I uploaded it to yt:
Door goes absolutely berserk when you get in the 10-stud radius [ROBLOX] - YouTube
I know how to debounce but I don’t know how you would debounce a runservice, does it work the same, how would it work, what would it look like?
script, server script under the door model:
local RP = script.Parent.PrimaryPart
local Radius = 10
local DetectionPart = script.Parent.Detectionpart
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
game:GetService("RunService").Heartbeat:Connect(function()--this is were the runservice thing is,
local Character = plr.Character or plr.CharacterAdded:Wait()
local door = {}
local HRP = Character.HumanoidRootPart
if (HRP.Position - DetectionPart.Position).Magnitude <= Radius then
local DoorTween = TweenService:Create(RP, TweenInfo.new(0.25,Enum.EasingStyle.Sine), {CFrame = RP.CFrame * CFrame.Angles(0,math.rad(-180),0)})
DoorTween:Play()
wait(0.2)
door.Open = true
elseif (HRP.Position - DetectionPart.Position).Magnitude > Radius and door.Open then
local EndDoorTween = TweenService:Create(RP, TweenInfo.new(0.5,Enum.EasingStyle.Sine), {CFrame = RP.CFrame * CFrame.Angles(0,math.rad(180),0)})
EndDoorTween:Play()
wait(0.2)
door.Open = false
end
end)
end)
So the problem is: it keeps running the code over and over again when we are in the 10-stud radius, so the tween is continually going a 180 degrees turn. Any way to debounce it, like I said before I have no idea how you would be able to, so you talented people here on the dev fourm probably do, or know whats wrong.