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 4 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:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local RS = game:GetService("ReplicatedStorage")
local NewPartEvent = RS:WaitForChild("NewPartEvent")
local debounce = false
local mousePosition = mouse.Hit.p



mouse.Button1Down:connect(function()

    if debounce == false then
        debounce = true


    NewPartEvent:FireServer(mousePosition)

        wait(2)
        debounce = false
    end
 end)

Server:

local RS = game:GetService("ReplicatedStorage")
local NewPartEvent = RS:WaitForChild("NewPartEvent")
local debounce = false


NewPartEvent.OnServerEvent:connect(function(plr, mousePosition)
    local partTwo = Instance.new("Part", workspace)
    partTwo.Position = mousePosition    
    print(mousePosition)
end)
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 — 4y

Answer this question