this script sometimes moves the part only locally instead of moving it globally all the time, how can i fix this?
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local billBoardGui = script.Parent
local runService = game:GetService(“RunService”)
local isMoving = false
local movePart
local part = billBoardGui.Adornee
if not isMoving then isMoving = true
movePart = runService.RenderStepped:Connect(function()
mouse.TargetFilter = part
part.Position = mouse.Hit.Position
end)
else
movePart:Disconnect()
mouse.TargetFilter = nil
isMoving = false
end
USI = game:GetService(“UserInputService”)
USI.InputBegan:Connect(function(input)
if isMoving == true then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
script:Destroy()
end
end
end)
You mean the part only moves on the client if thats the case then use a remoteEvent
-- Client side
local Drag = game:GetService("ReplicatedStorage"):FindFirstChild("DragEvent")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local billBoardGui = script.Parent
local isMoving = false
local movePart
local part = billBoardGui.Adornee
USI = game:GetService("UserInputService")
USI.InputBegan:Connect(function(input)
if isMoving == true then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
script:Destroy()
end
end
end)
if not isMoving then
isMoving = true
while wait(0.05) and isMoving do
mouse.TargetFilter = part
Drag:FireServer(part,mouse.Hit.Position)
end
else
mouse.TargetFilter = nil
isMoving = false
end
-- Server Side
local Drag = game:GetService("ReplicatedStorage"):FindFirstChild("DragEvent")
Drag.OnServerEvent:Connect(Function(player,part,nextpos)
part.position = nextpos
end)
You should avoid to send a request to a remoteEvent at each RenderStepped since it’s probably gonna overload the game and cause all remoteEvent to be ratelimited. You could however send the final position when the user stop moving the ball trought a remoteEvent. Another alternative would be to use Network Ownership
there are some things that make this not work, like where is nextpos specified or how do i create this so more scripts access their own parts with the RemoteEvent instead of just being one