Hello yet again! I am COWTACO, a fellow scripter and this time I’ve encountered an issue that I couldn’t really manage to solve and I’d be glad if anybody could assist me towards solving it, as it would mean the world to me.
Recently I followed a tutorial in regards to making a lightning powerup, however within that video there wasn’t really any indication as to how you can make shoot it from your character’s hands to your mouse.Hit.Position, so I tried to do so. I did manage to shoot it from my character’s hands, but it never reached my mouse Position and stayed to my player’s arms. I suggest taking a look at the tutorial as it may help us further into solving this issue.
Video Link: ROBLOX SCRIPTING TUTORIAL | CREATING ANIME LIGHTNING - YouTube
Issue Link: https://gyazo.com/627f77b3739107d204f563c06ac29cb1
I tried using a line of code I’ve used for my projectile, but it didn’t work. Please do keep in mind that this game is 2.5D and the lightning will only travel within the x, y axis as the Z axis is locked.
Module Script:
local module = {}
module.createLightning = function(startPos, endPos, segements)
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local mouse = Player:GetMouse()
local mousePos = mouse.Hit.Position
local points = {}
local Model = Instance.new("Model")
Model.Name = "Lightning"
Model.Parent = game.Workspace
for i = 0, segements do
local offset = Vector3.new(math.random(-1, 1), math.random(-1, 1), 0)
local Origin = Player.Character["Right Arm"]
local Start = Origin.Position
local Position = startPos + (endPos - startPos).Unit * i * 1.2 * Vector3.new(CFrame.new(mouse.Hit.Position.X, mouse.Hit.Position.Y, Player.Character.HumanoidRootPart.CFrame.LookVector))
if i == 0 or i == segements then
offset = Vector3.new(0,0,0)
end
points[#points + 1] = Position + offset
end
for i = 1, #points do
if points[i + 1] ~= nil then
local Lightning = script.Lightning:Clone()
Lightning.Size = Vector3.new(0.25,0.25, (points[i] - points[i + 1]).Magnitude)
Lightning.CFrame = CFrame.new(((points[i] + points[i+1]) / 2), points[i + 1])
Lightning.Parent = Model
end
end
return Model
end
return module
local Module = require(game.ReplicatedStorage.Scripts.ModuleScript)
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character
local UserInputService = game:GetService("UserInputService")
local mouse = Player:GetMouse()
local mousePos = mouse.Hit.Position
local function Lightning()
coroutine.wrap(function()
while UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1) do
local MouseToCharacterPosition = Player.Character.HumanoidRootPart.CFrame:PointToObjectSpace(mouse.Hit.Position)
local Zaxis = MouseToCharacterPosition.Z
if Zaxis > 0 or Zaxis > -7 then return end
if Zaxis < -7 then
task.wait(0.2)
local Position = Vector3.new(mouse.Hit.Position.X, mouse.Hit.Position.Y, Player.Character.HumanoidRootPart.CFrame.LookVector)
local Model = Module.createLightning(Player.Character["Right Arm"].Position, Position, 10)
for _, Part in pairs(Model:GetChildren()) do
local Fade = TweenService:Create(Part, TweenInfo.new(0.2, Enum.EasingStyle.Bounce), {Transparency = 1})
Fade:Play()
Fade:Destroy()
end
game:GetService("Debris"):AddItem(Model, 0.2)
end
end
end) ()
end
UserInputService.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
Lightning()
local LightningEvent = game.ReplicatedStorage.CharacterEvents.COWTACOLightning
LightningEvent:FireServer()
end
end)
There are no errors in the output and everything works as intended except for the lightning which doesn’t move to the mouse Position.