So I started scripting very recently and this is my first working script, I’m looking to recreate Swains E from league of legends.
The moves goes as this
I launch an attack that goes a certain distance and back to me (This works fine)
The arm does damage while going through people and if it hits them on the way back to me it roots them in place, putting the arm under the person like it’s holding them
And upon recast of the item while they’re rooted they are brought to me like a pull.
Now the things I need help with to add to the script are
- How to make the arm face the direction it’s going in and back
- How to make the arm grab people and root them in place on the way back
- How to make it so it brings them to me when I recast while they’re rooted
Also any help in improving the script is also appreciated
If you could explain why you used some of the stuff aswell would be appreciated since I’m a beginner and uneducated about most things
The input script -
local swainTool = script.Parent
local SwainAttack = game.ReplicatedStorage.SwainAttack
local players = game:GetService("Players")
local player = players.LocalPlayer
local Mouse = player:GetMouse()
debounce = true
swainTool.Activated:Connect(function()
local MousePosition = Mouse.Hit
local mag1 = (player.Character.HumanoidRootPart.Position - MousePosition.p).Magnitude
local direction = (MousePosition.p - player.Character.HumanoidRootPart.Position).Unit
if debounce == true then
debounce = false
SwainAttack:FireServer(direction)
wait(4)
debounce = true
end
end)
and the script itself
local swainTool = script.Parent
local swainAttack = game.ReplicatedStorage.SwainAttack
local swainArm = game.ReplicatedStorage.SwainArm
local Mouse = game:GetService("MouseService")
local tweenService = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(
0.6,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
false,
0
)
local tweeninfo2 = TweenInfo.new(
0.3,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
false,
0
)
local RATE_PER_SECOND = 2
local RunService = game:GetService("RunService")
local connection
swainAttack.OnServerEvent:Connect(function(player, direction)
local swainArm2 = swainArm:Clone()
swainArm2.Parent = workspace
swainArm2.Position = player.Character.HumanoidRootPart.Position
local goals = {CFrame = player.Character.HumanoidRootPart.CFrame + (Vector3.new(direction.X *30,direction.Y, direction.Z * 30))}
local tween = tweenService:Create(swainArm2, tweeninfo, goals)
tween:Play()
local function onHeartbeat(step)
local goals2 = {CFrame = player.Character.HumanoidRootPart.CFrame}
local tween2 = tweenService:Create(swainArm2, tweeninfo2, goals2)
local increment = RATE_PER_SECOND * step
if tween.PlaybackState == Enum.PlaybackState.Completed then
tween2:Play()
end
wait(0.6)
tween2:Cancel()
if tween2.PlaybackState == Enum.PlaybackState.Cancelled then
swainArm2:Destroy()
connection:Disconnect()
end
end
connection = RunService.Heartbeat:Connect(onHeartbeat)
end)