Answered by
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
1 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
2 | local player = game.Players.LocalPlayer |
3 | local mouse = player:GetMouse() |
5 | mouse.Button 1 Down:Connect( function () |
6 | local spellEvent = ReplicatedStorage.Remotes.Spell |
7 | spellEvent:FireServer(mouse.Hit.Position) |
for server
1 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
2 | local spellEvent = ReplicatedStorage.Remotes.Spell |
4 | spellEvent.OnServerEvent:Connect( function (_, position) |
5 | local spell = Instance.new( "Explosion" ) |
6 | spell.Position = position |
7 | spell.Parent = game.Workspace |