Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Updating a Player's Position?

Hello, I am trying to send the player's mouse position to the client's side through Remote Events, but there is a problem. I want to update the mouse's position on both the Client-side and Server-side but I am only capable of doing this in the Client-side, is there any possible way to update the position in both sides every second with the same remote event? Position = pos

Client Side

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local tool = script.Parent.Parent
local mouse = player:GetMouse()
local enabled1 = true
local pending = false

local requirement = game.ReplicatedStorage.LevelRequirements.ReqNA.Value
local upgrade1 = game.ReplicatedStorage.LevelRequirements.ReqUM1.Value
local upgrade2 = game.ReplicatedStorage.LevelRequirements.ReqUM2.Value
local upgrade3 = game.ReplicatedStorage.LevelRequirements.ReqUM3.Value

function onKeyDown(key)
if enabled1 == true then
local button = key:lower()
if key == "e" then
if tool.Active == true then
if player == nil then return end
if enabled1 == false then return end
if player.Stats.move.Value == 1 then return end

enabled1 = false
pending = true
player.Stats.move.Value = 1
local pos = mouse.Hit.p
local level = player.Stats.level.Value
local subject = script:findFirstChild("Move1")
subject:FireServer(pos, level, upgrade1, upgrade2, upgrade3)

Server Side

local subject = script.Parent:findFirstChild("Move1") 
local subjectR = script.Parent:findFirstChild("Move1R") 
local tablesAnim = {}

local function subjectFired(player, pos, level, upgrade1, upgrade2, upgrade3)

1 answer

✓ Accepted answer

You can fire an event every time the mouse changes. You must also include the position of the mouse. For example, it can look something like this:

This is an example. It might look something like this: LocalScript:

local mouse = game:GetService("Players").LocalPlayer:GetMouse()
mouse.Changed:Connect(function() -- When mouse or mouse attributes changed...
    local newPosition = mouse.Hit.p
    game.ReplicatedStorage.PosMouseUpdateEvent:FireServer(newPosition) -- Updated with new mouse position
end)

ServerScript:

game.ReplicatedStorage.PosMouseUpdateEvent.OnServerEvent:Connect(function(Pos)
-- do whatever with pos
print(Pos.." is the mouse position.")
end)

Again, for your script, it may not look the exact same as this. This is just an idea of how it may look like. Please tell me if this worked or didn't work.

Thank you.

Edit - I think this can suit your script. It may be as simple as that.

mouse.Changed:Connect(function()
    subject:FireServer(pos, level, upgrade1, upgrade2, upgrade3)
end)

7 comments

0

Or... You can leave the subject:FireServer out of the Changed function, and add a new line thats INSIDE the server and that is: subject:FireServer(pos) as a seperate one in the changed function so nothing happens to level, upgrades, etc.

0

Your answer is still wrong.

0

Both wrong.

0

Fixed it myself anyways, so I'll end this question.

0

If this didn't work, then you shouldn't have accepted this answer lol.

0

its benefiting you don't complain.

0

lol ok

This discussion is preserved as it was. New answers, comments, and votes are closed.