-
What do you want to achieve?
I want to make it so when the player holds Z the player gets locked in the place and his character will face wherever the mouse is aiming at. And when the player releases the key a projectile would be created infront of the player and it would go forever until it hits something and when it does hits it plays VFX -
What is the issue?
The issue is when I release the Z button the projectile is created in the middle of the place, instead of infront the player like i want, the particles work fine and also the animations. -
What solutions have you tried so far?
I tried talking to some developers but they said they didnt know what to do.
local TW = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local CameraShaker = require(script.Parent.Parent.Modules.CameraShakeHandler)
local Utilities = require(script.Parent.Parent.Modules.Utils)
local Debounce = false
local Holding = false
local AnimationCache = {}
local function LoadAnimTrack(Hum, Animation, Data)
if not AnimationCache[Animation] then
AnimationCache[Animation] = Hum:LoadAnimation(Animation)
AnimationCache[Animation].Looped = Data.Looped or false
AnimationCache[Animation].Priority = Data.AnimationPriority or Enum.AnimationPriority.Action
end
return AnimationCache[Animation]
end
local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Include
local Skill = {}
Skill.Activate = function()
local Character = game:GetService("Players").LocalPlayer.Character
local RootPart = Character.HumanoidRootPart
local Hum = Character.Humanoid
if Debounce == false then
Debounce = true
Holding = true
local Animation = script.Hold
local AnimTrack = LoadAnimTrack(Hum, Animation, {Looped = true})
AnimTrack:Play()
local Bp = Instance.new("BodyPosition")
Bp.Parent = RootPart
Bp.Name = "HoldCharBp"
Bp.MaxForce = Vector3.one * 4e4
Bp.D = 150
Bp.Position = RootPart.Position
local Bg = Instance.new("BodyGyro")
Bg.Parent = RootPart
Bg.Name = "HoldCharBg"
Bg.MaxTorque = Vector3.one * 4e4
Bg.CFrame = CFrame.lookAt(RootPart.Position, game.Players.LocalPlayer:GetMouse().Hit.Position)
spawn(function()
while Holding do
Bg.CFrame = CFrame.lookAt(RootPart.Position, game.Players.LocalPlayer:GetMouse().Hit.Position)
task.wait()
end
Bg:Destroy()
Bp:Destroy()
end)
end
end
Skill.End = function()
local Character = game:GetService("Players").LocalPlayer.Character
local RootPart = Character.HumanoidRootPart
local Hum = Character.Humanoid
RayParams.FilterDescendantsInstances = {workspace.Map}
if Holding == true and Debounce == true then
Holding = false
delay(2, function()
Debounce = false
end)
local Animation = script.Hold
local AnimTrack = LoadAnimTrack(Hum, Animation, {Looped = true})
AnimTrack:Stop()
local Animation = script.Release
local AnimTrack = LoadAnimTrack(Hum, Animation, {Looped = false})
AnimTrack:Play()
delay(0.183, function()
local RootFX = script.Holder.RootFX:Clone()
Utilities.Particle_Setup({Holder = RootFX, Type = "Emit"})
task.delay(1.5, function()
RootFX:Destroy()
end)
CameraShaker.ShakeOnce({3.5,3.5,0.2,0.55})
local EndPos = (RootPart.CFrame * CFrame.new(0,0,-1000)).Position
local Projectile = script.Projectile:Clone()
Projectile.Parent = workspace.Ignore
Projectile.CFrame = CFrame.lookAt(RootFX.WorldPosition, EndPos)
Utilities.Particle_Setup({Holder = Projectile, Type = "Enable", Bool = true})
local StartTick = tick()
local Velocity = (Projectile.Position - EndPos).Unit * -50
local Connection
Connection = RunService.RenderStepped:Connect(function(dt)
if tick() - StartTick > 2 then
Utilities.Particle_Setup({Holder = Projectile, Type = "Enable", Bool = false})
Projectile.Transparency = 1
local Tween = TW:Create(Projectile.Light.PointLight, TweenInfo.new(0.35), {Brightness = 0})
Tween:Play()
Tween:Destroy()
delay(2,function()
Projectile:Destroy()
end)
Connection:Disconnect()
return
end
local Result = workspace:Raycast(Projectile.Position, Velocity * dt -Vector3.new(0,0,0) * dt * dt, RayParams)
if Result then
Utilities.Particle_Setup({Holder = Projectile.Explosion, Type = "Emit"})
Utilities.Particle_Setup({Holder = Projectile, Type = "Enable", Bool = false})
Projectile.Transparency = 1
local Tween = TW:Create(Projectile.Light.PointLight, TweenInfo.new(0.35), {Brightness = 0})
Tween:Play()
Tween:Destroy()
delay(2,function()
Projectile:Destroy()
end)
CameraShaker.ShakeOnce({7,7,0.1,0.55})
Connection:Disconnect()
return
else
Projectile.Position = Projectile.Position + Velocity * dt -Vector3.new(0,0,0) * dt * dt
Velocity += -Vector3.new(0,0,0) * dt
end
end)
end)
end
end
return Skill