Send updated information to server?

so i have a remote event, it gives the server the mouse.hit.postion when fired. But the player’s mouse.hit.position might change, is there a way i can send the information a few seconds after?

1 Like

Is this the sort of thing you are looking for?

--Local Script
game.Workspace.RemoteEvent:FireServer(--whatever you want to pass back--)
--Server Script
game.Workspace.RemoteEvent.OnServerEvent:Connect(function(player, --whatever you passed back--)
end)
2 Likes

it already has a remote event. i think i wasn’t being clear. so here is what i want to do:

player fires event and sends information

server receives and does ability gfx and stuff

server uses OLD information from the client

im trying to have maybe the server ask for the information when it needs it?

1 Like

If it needs to have it everytime the player clicks, use UserInputService.InputBegan and fire it there

1 Like

What you could do is within a InputChanged event within UserInputService, is fire a remote event to the server with the mouse position in it (I think you can get it from the inputObject parameter in there)?

1 Like

it does send one, but since the player’s mouse moves, the server would have to get the player’s mouse.hit THAT INSTANT

1 Like

Then InputChanged should be what you definitely need, as that will listen for ANY input from any input device the player has, mouse included. I’ll whip up an example script, one moment please. :slight_smile:

1 Like

Then fire it every Heartbeat
The quick brown fox…

1 Like

i might have to do that unless the server can request information

1 Like

Use .OnClientEvent and FireClient Which would be more optimized than firing every Heartbeat
But also slower considering the delay between client and server remote events firing.

1 Like

i think you all are a bit misunderstanding

when the player click, the event fires and sends mouse.hit.pos

but the server won’t need it until 4 seconds later, and the server ended up using mouse.hit.pos from four seconds ago

i would need for the server to ask the client for new mouse.hit.pos

1 Like

Have a go at this:

Local script:

local UIS = game:GetService("UserInputService")
local remoteEventExample = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEventExample")

UIS.InputChanged:Connect(function(inputObj: InputObject, gameProcessedEvent: boolean)
	remoteEventExample:FireServer(inputObj.Position)
end)

Server script:

local remoteEventExample = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEventExample")

remoteEventExample.OnServerEvent:Connect(function(player, playerMousePosition)
	print(player.Name .. tostring(playerMousePosition))
end)

Explorer:
image

yeah i used that, lemme show you my script:

local event = game.ReplicatedStorage.Events.FireEvent
local tweenservice = game:GetService("TweenService")
event.OnServerEvent:Connect(function(plr,Mouse,look)


	local part = game.ReplicatedStorage.Ball:Clone()
	part.Parent = workspace
	part.CFrame = plr.Character.Torso.CFrame*CFrame.new(0,-5,-3) 

	local tweenInfo = TweenInfo.new(0.3) -- Change the duration as needed
	local tween = tweenservice:Create(part, tweenInfo, {CFrame = CFrame.new(plr.Character.Head.Position + plr.Character.Head.CFrame.LookVector * 6)})



		local downForce = - part:GetMass() * workspace.Gravity + 300
		local force = -downForce
		part.Value.Value = plr.Name
		local bodyForce = Instance.new("BodyForce")
		bodyForce.Force = Vector3.new(0,force,0)
		bodyForce.Parent = part
		tween:Play()
		wait(4)
		part.Velocity = CFrame.new(plr.Character.HumanoidRootPart.Position, Mouse).LookVector * 200 (old information)
	

end)

client:

mouse.Button1Down:Connect(function()
	if not db and script.Parent.Humanoid.Health ~= 0 and not wall then
		db = true

		script.Parent.Torso.Anchored = true
		script.Parent.Humanoid.WalkSpeed = 0
		wait(0.15)
		event:FireServer(mouse.Hit.Position,mouse.Hit.LookVector)
		anim:Play()
		wait(0.5)
		script.Parent.Torso.Anchored = false
		script.Parent.Humanoid.WalkSpeed = 20
		wait(1)
		db =false
	
	end
	
end)


as you can see, the server is using the mouse.pos 4 seconds ago, my friend said remote functions might work, not sure though

Remote functions WOULD work, but it’s highly recommended you don’t use them from server → client, because it’s not guaranteed you get a return from the client you’re firing to, MEANING your server code is just left frozen and vulnerable.

What I’d do is, fire to the server when a player clicks their mousebutton1 down, store it in a collection of click points (in a table, with the player being the key and a list of click positions?) and just pop from the list in 4 second intervals? Maybe that works.

EDIT: OH I’M DUMB, I get what you mean now, you want when the player clicks, wait 4 seconds, and THEN do the thing with the projectile. Okay I’m with you.

maybe client invoke the server 4 seconds later willingly? and the server use that

Okay, so what I’d do is:

  • Listen for a mouse click, using InputBegan.
  • Wait 4 seconds in that function with InputBegan.
  • THEN fire to the server to do the projectile stuff.

uh the event kinda starts the projectile stuff

you could try sending the remote event twice

  1. client tells the server to start
  2. server waits 4 seconds and then fires to the client
  3. client gets the server request and sends a second request to the server
  4. server waits for that connection and continues what you wanted it with the latest mouse position (disregarding lag/ping)

Try this. :slight_smile:

local UIS = game:GetService("UserInputService")

local mouseHitPosition = Vector3.new()
local mouseHitLookVector = Vector3.new()


-- We're going to use this one to update the current mouse position so we know what the mouse position it at the time we need it!
UIS.InputChanged:Connect(function(inputObj: InputObject, gameProcessedEvent: boolean)
	if inputObj.UserInputType == Enum.UserInputType.MouseMovement then
		local mouse = game.Players.LocalPlayer:GetMouse()
		mouseHitPosition = mouse.Hit.Position
		mouseHitLookVector = mouse.Hit.LookVector
	end
end)

-- This is going to be used to detect the mouse button click.
UIS.InputBegan:Connect(function(inputObj: InputObject, gameProcessedEvent: boolean)
	if inputObj.UserInputType == Enum.UserInputType.MouseButton1 then
		if not db and script.Parent.Humanoid.Health ~= 0 and not wall then
			db = true
			task.wait(4) -- Wait 4 seconds until the server would need it.

			script.Parent.Torso.Anchored = true
			script.Parent.Humanoid.WalkSpeed = 0
			wait(0.15)
			event:FireServer(mouseHitPosition,mouseHitLookVector)
			anim:Play()
			wait(0.5)
			
			script.Parent.Torso.Anchored = false
			script.Parent.Humanoid.WalkSpeed = 20
			wait(1)
			
			db =false

		end
	end
end)

I’ll see if I can get it to work using entirely UserInputService instead of :GetMouse() (since it shouldn’t be used for new work) but what I’ve made should do the job.