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

How do you find the mouse's vector3 value?

Asked by 4 years ago
Edited 4 years ago

Hi, I'm trying to set a parts position to the mouse's position. I've tried using mouse.Target, mouse.Hit and mouse.X / mouse.Y.

Current code:

01local player = game.Players.LocalPlayer
02local mouse = player:GetMouse()
03local SpellPart = game.Workspace.Spell
04 
05 
06local function SpellSummon()
07    local MT = mouse.Target
08 
09    SpellPart.Position = MT
10 
11end
12 
13mouse.Button1Down:Connect(function()
14    SpellSummon()
15end)

Thanks for reading!

0
Are you trying to get the mouse's current position bestshot123 38 — 4y
0
Because if you are you can use this function to get its position - local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.Move:Connect(function(move) print(mouse.X) print(mouse.Y) end) bestshot123 38 — 4y

1 answer

Log in to vote
1
Answered by
Speedmask 661 Moderation Voter
4 years ago
Edited 4 years ago

hey, you're already on the right track. the reason this isn't working is because you are trying to create a part from the client, or from the player's computer. this is a whole topic all in itself and I suggest you read this article and this article, as it prevents exploiters.

what you will need to do this behavior is an object called a remote event, which is essentially a signal that allows both types of scripts to communicate. you can put a remote event in ReplicatedStorage where both the player's computer and the server can see it. you will need two different scripts for the client and the server (aka a localscript and a serverscript)

for client

1local ReplicatedStorage = game:GetService("ReplicatedStorage")
2local player = game.Players.LocalPlayer
3local mouse = player:GetMouse()
4 
5mouse.Button1Down:Connect(function()
6    local spellEvent = ReplicatedStorage.Remotes.Spell -- this is your remote event, I like to use a folder called Remotes
7    spellEvent:FireServer(mouse.Hit.Position)
8end)

for server

1local ReplicatedStorage = game:GetService("ReplicatedStorage")
2local spellEvent = ReplicatedStorage.Remotes.Spell
3 
4spellEvent.OnServerEvent:Connect(function(_, position)
5    local spell = Instance.new("Explosion") -- you can replace this explosion with your part
6    spell.Position = position
7    spell.Parent = game.Workspace
8end)
0
Thanks! TheStarRblx 27 — 4y
Ad

Answer this question