I need help creating a script to put into a sword that whenever I press "Z" it will create red particles where my mouse is, and follow my mouse- I would also like for the particles to do damage. Particles need to be able to disappear upon me press Z again.
Any ideas? I'm not sure how to do any of this, so can someone direct me to a source of information I can use to help?
Or can someone help me figure out the basis so I can stem off of it?
Use a Local Script
inserted into some Service that gets replicated to the player, like StarterGui
.
Now that we're using a Local Script, we can get the Local Player
and the player's mouse
. We would do this like so,
-- Local Script In StarterGui local plr = game.Players.LocalPlayer local mouse = plr:GetMouse()
Use user input service to detect the Z button being pressed.
Insert an invisible part that follows the mouse, and place the particles in the part.
Use mouse.Hit to get the CFrame of the mouse's world CFrame. This is very important. You would do the following to make a part where the mouse is in the world,
-- Local Script In StarterGui local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local p = Instance.new("Part", game.Workspace) p.CFrame = mouse.Hit
But this wouldn't really work if mouse.Hit is nil, and also because this isn't on a loop or event.
So Also,
Use a Mouse move event. Similar to so,
-- Local Script In StarterGui local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() mouse.Move:connect(function() if mouse.Hit ~= nil then local p = Instance.new("Part", game.Workspace) p.CFrame = mouse.Hit end end)
Those are some of my ideas. I would provide an complete answer if I had more time. Later, if you're still having trouble, I could provide a better answer.
Good Luck!