I am trying to create an object that can be directly oriented from the position of the mouse, only problem is that I also want it to be server side, and since you can’t get the mouse onto server side, as it only exists on the client.
I’ve tried this before, and the thing is that I want it to be constantly updated, without repeatedly firing the same event over and over, until the key is no longer being pressed.
You can use CFrame, and While the mouse button 1 is getting pressed, then you can do
local mousedown = false
local part
local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
mousedown = true
while mousedown do
--add the stuff of the orientation you want to do here
part = theparthere
wait()
end
while mousedown do
game.ReplicatedStorage.Event:FireServer(Part, Part.CFrame)
wait(0.3)
end)
--Server Side
game.ReplicatedStorage.Event.OnServerEvent:Connect(function(object, ok)
local tween = game:GetService("TweenService")
tween:Create(object, TweenInfo.new(1), {CFrame = ok}):Play()
end)
This wouldn’t be exactly on the moment but well, you can change the wait to less, but, I don’t know what’s the problem about firing an event over an over? like, you could use a DistanceFromCharacter, for this applies for nearby players, like something like this.
game.ReplicatedStorage.Event.OnServerEvent:Connect(function(object, ok)
for i,v in pairs(game.Players:GetPlayers()) do
if v:DistanceFromCharacter(object.Position) <= 80 then
spawn(function()
local tween = game:GetService("TweenService")
tween:Create(object, TweenInfo.new(1), {CFrame = ok}):Play()
end)
end
end
end)
Your specific solution doesn’t tie towards his request in such a manor he asked for. However, it’d probably be the most suitable as the NetworkOwnership alternative didn’t work. I’d just like to add, that you might want to do server sided sanity checks instead of just trusting the client 100%
Like I said, firing the remote repeatedly would be most suitable, I was just stating that it didn’t meet the OP owner’s request.
I’d also like to point out that you’re code is missing an end, and the second while statement will never be fired
I am not using a tool, I am using a local script to grab the inputs with a server script to create and do the necessary things to the object.
I would also like to say that this should be 100% possible without using your method, as I’ve seen some games do this, just to name one off the top of my head, Elemental Battlegrounds. There is a specific move that follows the mouse position that anyone on the game can see, as I have tried to attack people and they could tell exactly where it was, and there wasn’t a big delay on the movements from the spell being cast to the part moving to my mouse.
So this can be done by using the SetNetworkOwnership along with BodyPosition and BodyGyro, just make sure the bodyposition max force is high enough to generate a higher responsiveness.-- Actually you should just be able to do this with setnetworkownership on it’s own as I just removed the body position and body gyro and updated the part’s position and it works fine.
-- Server Code used to test
game.Players.PlayerAdded:Wait()
script.Parent:SetNetworkOwner(game.Players:GetPlayers()[1])
-- Client Code used to test
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
Player.CharacterAdded:Wait()
game:GetService("RunService").RenderStepped:Connect(function()
workspace.Meep.CFrame = CFrame.new(Mouse.Hit.p)
end)