Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local Remote = ReplicatedStorage.Fired
local Mouse = plr:GetMouse()

local Debounce = true
local Key = 'R'

UserInputService.InputBegan:Connect(function(Input, IsTyping)
 if IsTyping then return end
 local KeyPressed = Input.KeyCode
 if KeyPressed == Enum.KeyCode[Key] and Debounce and Char then
  Debounce = false
  Remote:FireServer(Mouse.Hit)
  wait(1)
  Debounce = true
 end
end)

Code for the attack itself

game.ReplicatedStorage.Fired.OnServerEvent:Connect(function(Player, Debounce)
	local Character = Player.Character or Player.CharacterAdded:wait()
	Debounce = true
	local LightBeam = Instance.new("Part")
	LightBeam.Name = "LightBeam"
	LightBeam.Size = Vector3.new(3,3,3)
	LightBeam.Shape = Enum.PartType.Cylinder
	LightBeam.Material = Enum.Material.Neon
	LightBeam.BrickColor = BrickColor.new("Cool yellow")
	LightBeam.CanCollide = false
	LightBeam.Parent = Character
	LightBeam.CFrame = Character.Torso.CFrame*CFrame.new(0,1,0)
	LightBeam.Anchored = true
	wait(.2)
	LightBeam.Size = Vector3.new(104,3,104)
	wait(2)
	LightBeam:Destroy()
end)

the game is set up to only use r6 models btw

1 comment

0

in line 12 use this code

3 answers

✓ Accepted answer

you could:

LightBeam.CFrame = Character:GetPrimaryPartCFrame()*CFrame.new(0,0,-3)

Use CFrame multiply with CFrame

local orientation = LightBeam.Orientation
local stud = 0 -- Change if you want LightBeam move forward or backward
local Ystud = 0 -- Change if you want LightBeam move up or down
LightBeam.CFrame = Character.Head.CFrame *CFrame.new(0,(-4.5)+(LightBeam.Size.Y/2)+Ystud,stud)

-create a local cframe

local 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

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

or you can put the cframe directly in RPosition

This discussion is preserved as it was. New answers, comments, and votes are closed.