Insta lazer projectile spawns in the middle of me?
Asked by
6 years ago Edited 6 years ago
Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).
I've already made a "Lightning bolt" which is just a long cilinder part that I've Inserted into Replicated Storage Called "LightningBolt"
Inside the Starter GUI I put this script in a local script
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | local UserInputService = game:GetService( "UserInputService" ) |
04 | local plr = game.Players.LocalPlayer |
05 | local Char = plr.Character or plr.CharacterAdded:Wait() |
06 | local Remote = ReplicatedStorage.LightningEvent |
07 | local Mouse = plr:GetMouse() |
11 | local Animation = Instance.new( "Animation" ) |
14 | UserInputService.InputBegan:Connect( function (Input, IsTyping) |
15 | if IsTyping then return end |
16 | local KeyPressed = Input.KeyCode |
17 | if KeyPressed = = Enum.KeyCode [ Key ] and Debounce and Char then |
19 | Remote:FireServer(Mouse.Hit) |
20 | local LoadAnimation = Char.Humanoid:LoadAnimation(Animation) |
And in Server Script services I put this script
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
04 | local Remote = ReplicatedStorage.LightningEvent |
05 | local Lightning = ReplicatedStorage.LightningBolt |
10 | local ServerDebounces = { } |
11 | Remote.OnServerEvent:Connect( function (plr, Mouse) |
12 | if not ServerDebounces [ plr ] then |
13 | ServerDebounces [ plr ] = true |
15 | local Char = plr.Character or plr.CharacterAdded:Wait() |
17 | local LightningClone = Lightning:Clone() |
18 | Lightning.CFrame = Char.HumanoidRootPart.CFrame * CFrame.new( 0 , 0 , 0 ) |
19 | Lightning.Parent = workspace |
23 | ServerDebounces [ plr ] = false |
27 | LightningClone.Touched:Connect( function (h) |
28 | if h.Parent:FindFirstChild( 'Humanoid' ) and h.Parent.Name ~ = plr.Name and Debounce then |
30 | local Enemy = h.Parent.Humanoid |
31 | Enemy:TakeDamage(Damage) |
33 | LightningClone.Effect.Enabled = false |
35 | LightningClone:Destroy() |
I know that there are still some things that are not needed and I can fix that latter, but I cant wrap my head around how to make the projectile that's pretty long start near me, and the other end where my curser is, this script just brings the middle of the "lazer" and places it infront of me, which isnt where I want it.
I honestly thought just taking away body-velocity and making a projectile script would work, but it seems Im not too bright