title title title title title title title
i tried renderstepped but didnt work, is there any alternitives for this?
title title title title title title title
i tried renderstepped but didnt work, is there any alternitives for this?
check the part’s magnitude (distance), constantly (loop)
how would you Do this?aaaaaaaaaaa
Part.Changed:Connect(function()
If Part.Position == targetPosition then
–code
end
end
i tried this but the changed event isnt firing, maybe cause im using a constraint to move it
it fires randomly at start and stops, i’d need it to fire everytime it changed to detect when its finished moving
Without while loop and server script
local RunService = game:GetService("RunService")
-- Define the target position
local targetPosition = Vector3.new(0, 10, 0)
-- Define the part you want to track
local part = workspace.Part
-- Define a threshold distance to determine when the part has reached the target
local threshold = 1 -- You can adjust this value
local function checkPosition()
local distance = (part.Position - targetPosition).magnitude
if distance <= threshold then
print("The part has reached the target position!")
-- Disconnect the event after the condition is met
connection:Disconnect()
end
end
-- Connect the function to the Heartbeat event
local connection = RunService.Heartbeat:Connect(checkPosition)
Thats good, but ideally we should find a method that works without loops at all.
Try getPropertyChangedSignal(), suposedly it has similar performance as changed().
would this pause other proccesses in the script? aaaa
Something like this ?
Elevator.PrimaryPart:GetPropertyChangedSignal("CFrame"):connect(function()
print("a")
end)
No, the code would not pause other processes in the script. It leverages the RunService.Heartbeat
event, which runs a function every frame without blocking other processes.
Sure, alternatively you could use a tween. Just set the time parameter to distance/speed.
Thank you seems to be working but how would i disconnect it if the variable starts it afterwards?
local function checkPosition()
local distance = (Elevator.PrimaryPart.Position.Y - Elevator.PrimaryPart:GetAttribute(RequestedFloor.Name))
print(distance, Elevator.PrimaryPart:GetAttribute("CurrentFloor"))
if distance <= 0 then
connection:Disconnect()
elevatorModule.OpenDoors(Elevator)
Elevator.PrimaryPart:SetAttribute("CurrentFloor", RequestedFloor.Name)
end
end
local connection = RunService.Heartbeat:Connect(checkPosition)
RenderStepped doesn’t work in servers, it’s only cliend-sided, however, you can use either Stepped or Heartbeat
local function checkPosition()
local distance = (Elevator.PrimaryPart.Position.Y - Elevator.PrimaryPart:GetAttribute(RequestedFloor.Name))
print(distance, Elevator.PrimaryPart:GetAttribute("CurrentFloor"))
if distance <= 0 then
elevatorModule.OpenDoors(Elevator)
Elevator.PrimaryPart:SetAttribute("CurrentFloor", RequestedFloor.Name)
return "Disconnect"
end
end
local connection = RunService.Heartbeat:Connect(function(deltaTime)
local connector = checkPosition()
if connector == "Disconnect" then
connection:Disconnect()
end
end)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.