Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Transferring mouse.Hit.p to the server?

Asked by 5 years ago

Hi, so I'm having some trouble transferring mouse.Hit.p from the client to the server. I'm trying to make a script that spawns a part where I click, but when I run it I get some weird errors. The part doesn't spawn where I click, but rather at a seemingly random point farther away. Also when I print mouse.Hit.p, it gives me the correct point the first time, but every other time I click it just prints the same point. What's up with this?

Client:

01local player = game.Players.LocalPlayer
02local mouse = player:GetMouse()
03local RS = game:GetService("ReplicatedStorage")
04local NewPartEvent = RS:WaitForChild("NewPartEvent")
05local debounce = false
06local mousePosition = mouse.Hit.p
07 
08 
09 
10mouse.Button1Down:connect(function()
11 
12    if debounce == false then
13        debounce = true
14 
15 
View all 21 lines...

Server:

01local RS = game:GetService("ReplicatedStorage")
02local NewPartEvent = RS:WaitForChild("NewPartEvent")
03local debounce = false
04 
05 
06NewPartEvent.OnServerEvent:connect(function(plr, mousePosition)
07    local partTwo = Instance.new("Part", workspace)
08    partTwo.Position = mousePosition   
09    print(mousePosition)
10end)
0
This is because you declared mouse.Hit.p once, not every time the mouse is clicked. This will cause a constant Vector. Just move line 6 into the Button1Down event Ziffixture 6913 — 5y

Answer this question