Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i make my light beam attack always start in front of the character?

Asked by 5 years ago

Sorry for the rough scripts, im fairly new, but what im trying to do is make a cylinder shaped object start in front of you and quickly expand outwards. my problem is that i cant figure out how to get it to go in front of you, and its always going across 1 of the axis.

Code for the local script that triggers the attack

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local UserInputService = game:GetService("UserInputService")
03local plr = game.Players.LocalPlayer
04local Char = plr.Character or plr.CharacterAdded:Wait()
05local Remote = ReplicatedStorage.Fired
06local Mouse = plr:GetMouse()
07 
08local Debounce = true
09local Key = 'R'
10 
11UserInputService.InputBegan:Connect(function(Input, IsTyping)
12 if IsTyping then return end
13 local KeyPressed = Input.KeyCode
14 if KeyPressed == Enum.KeyCode[Key] and Debounce and Char then
15  Debounce = false
16  Remote:FireServer(Mouse.Hit)
17  wait(1)
18  Debounce = true
19 end
20end)

Code for the attack itself

01game.ReplicatedStorage.Fired.OnServerEvent:Connect(function(Player, Debounce)
02    local Character = Player.Character or Player.CharacterAdded:wait()
03    Debounce = true
04    local LightBeam = Instance.new("Part")
05    LightBeam.Name = "LightBeam"
06    LightBeam.Size = Vector3.new(3,3,3)
07    LightBeam.Shape = Enum.PartType.Cylinder
08    LightBeam.Material = Enum.Material.Neon
09    LightBeam.BrickColor = BrickColor.new("Cool yellow")
10    LightBeam.CanCollide = false
11    LightBeam.Parent = Character
12    LightBeam.CFrame = Character.Torso.CFrame*CFrame.new(0,1,0)
13    LightBeam.Anchored = true
14    wait(.2)
15    LightBeam.Size = Vector3.new(104,3,104)
16    wait(2)
17    LightBeam:Destroy()
18end)

the game is set up to only use r6 models btw

0
in line 12 use this code PepeElToro41 132 — 5y

3 answers

Log in to vote
0
Answered by
Is_Hunter 152
5 years ago

you could:

1LightBeam.CFrame = Character:GetPrimaryPartCFrame()*CFrame.new(0,0,-3)
Ad
Log in to vote
1
Answered by
EteraW 77
5 years ago

Use CFrame multiply with CFrame

1local orientation = LightBeam.Orientation
2local stud = 0 -- Change if you want LightBeam move forward or backward
3local Ystud = 0 -- Change if you want LightBeam move up or down
4LightBeam.CFrame = Character.Head.CFrame *CFrame.new(0,(-4.5)+(LightBeam.Size.Y/2)+Ystud,stud)
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

-create a local cframe

1local RPosition = CFrame.new(0,0,1)

the numbers in the cframe are the relative coordinates that will be added

in line 12 use this code

1LightBeam.CFrame = Character.Torso.CFrame:ToWorldSpace(RPosition)

or you can put the cframe directly in RPosition

Answer this question