✓ Accepted answer
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
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")
spell.Position = position
spell.Parent = game.Workspace
end)
2 comments
Are you trying to get the mouse's current position
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)