I have 2 questions about it, so first one is im done with the code that when you click on a prop it follows your mouse but i want it to have a limit on how far it goes on xyz, i would like to know that and there is this something called setnetworkowner what’s that? and would it be necessary?
Script I made:
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
local Target = mouse.Target
print("clicked")
if not Target then return end
if Target then
if Target.Parent == game.Workspace.Props then
mouse.TargetFilter = Target
local Force = Target.AlignPosition
local Attachment1 = Target.Attachment
while wait() do
Force.Position = mouse.Hit.Position
Target.CFrame = CFrame.new(Target.AlignPosition.Position)
end
else
print("not a prop")
end
else
print("no target")
end
end)
SetNetworkOwner() is a method you can call on a BasePart to determine who should simulate the physics. By default, the server will. In some games, you may notice a slight jitter on moving parts when they get close to a player - this is network ownership being changed, or delegated to the closest client to help lessen the server’s workload.
I’m not sure exactly how you want to limit the prop, but one method could be a simple distance check from the player’s character to the prop.
local MAX_DISTANCE = 128
local rootPartPosition = player.Character.PrimaryPart.Position -- Position of the HumanoidRootPart.
local targetPosition = Target.Position
local distance = (targetPosition - rootPartPosition).Magnitude
if distance < MAX_DISTANCE then
-- move the prop.
else
-- prop is too far.
end
I get SetNetworkOwner() now, thank you but for the uh limit i think you got me wrong…i meant when im using the telekinesis and the part is floating how do i make it float on air and not just stick to the ground like this
as everytime i try to lift it to the sky it just goes to the end of the map that’s why i asked for a limit to how far it can telekinate, so i can succesfully raise it to the air
You could try using a raycast. If the raycast hits an object youd set the object being telekenetically controlled to the hit position minus half of the telekenetic objects bounds size, otherwise youd set it to the end of the raycast.
My apologies! I played around real quick and made this:
When the part is clicked, I start updating it with RenderStepped. It’s XYZ rotation is randomly incremented while following the motion of a sine wave for some bobbing using delta time.
Yess that’s what I quite literally wanted…is there a possible guide through you could show me?
Would really appreciate it I think i messed up some parts
I’ve added comments to the main points of the code I used to animate the part, which will guide you through what’s happening. Hopefully it’s good enough for you to learn from and isn’t just a case of copy/pasting.
StartUpdating() is invoked when the player clicks on the part. Additionally, StopUpdating()(not shown as I think it’s self-explanatory) simply disconnects the connection when the player stops holding the mouse button (using UserInputService for this: InputBegan and InputEnded).
Code
local AMPLITUDE = 0.5 -- Higher value, larger bobbing effect.
local FREQUENCY = 0.25 -- Higher value, faster bobbing effect.
local timeElapsed = 0
local xAngle, yAngle, zAngle = 0, 0, 0
local function StartUpdating()
updateConnection = runService.RenderStepped:Connect(function( dt )
if not target then return end
timeElapsed += dt % (1/timeElapsed)
-- Randomly increment each axis.
xAngle += math.rad(math.random(5) / 10)
yAngle += math.rad(math.random(5) / 10)
zAngle += math.rad(math.random(5) / 10)
-- Update part to be 3 studs above the mouse's position, then proceed to
-- add sine wave for bobbing and then angular rotation.
target.CFrame = target.CFrame:Lerp(
mouse.Hit * CFrame.new(0, 3, 0) * CFrame.new(0, AMPLITUDE * math.sin((math.pi*2) * FREQUENCY * timeElapsed), 0)
* CFrame.Angles(xAngle, yAngle, zAngle),
0.2
)
end)
end
I have never used math.sin and pi ever in my scripting phase nor have I used dt % and all that stuff like honestly I always hate using math in scripting had a big problem with it so sadly this code is a bit uh like hard for me to understand, Sorry but if there is another way or idk something that can get me to understand the concept of what’s happening, Like the reason why I sent this is because I fr wanna learn these kinda stuff to expand and not copy the code
You can use this Desmos graph to view what happens to a sine wave when you change the amplitude and frequency. This is the bobbing motion the part will follow. Imagine the part riding the graphed sine wave from left to right, except only we’re using the sine wave for the Y axis.
Delta time (dt) is the time passed between each frame. We increment the timeElapsed variable with this and perform some modulo operations, which helps with losing precision over time. This last part may not even be necessary, it was a snippet of code I pulled from a relevant question on Stack Overflow. You could simply just use dt, with timeElapsed += dt.