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:
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local SpellPart = game.Workspace.Spell local function SpellSummon() local MT = mouse.Target SpellPart.Position = MT end mouse.Button1Down:Connect(function() SpellSummon() end)
Thanks for reading!
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
local ReplicatedStorage = game:GetService("ReplicatedStorage") local player = game.Players.LocalPlayer local mouse = player:GetMouse() mouse.Button1Down:Connect(function() local spellEvent = ReplicatedStorage.Remotes.Spell -- this is your remote event, I like to use a folder called Remotes spellEvent:FireServer(mouse.Hit.Position) end)
for server
local ReplicatedStorage = game:GetService("ReplicatedStorage") local spellEvent = ReplicatedStorage.Remotes.Spell spellEvent.OnServerEvent:Connect(function(_, position) local spell = Instance.new("Explosion") -- you can replace this explosion with your part spell.Position = position spell.Parent = game.Workspace end)