Hello dev’s!
Today i tried make illusion of gun animation with postion, but i get this:
I want easy way to animate gun.
Local script:
local plr = game:GetService("Players").LocalPlayer
local pr = script.Parent
local rs = game.ReplicatedStorage.Shot
local m = plr:GetMouse()
local db = false
local am = 17
local al = nil
local al1
pr.Activated:Connect(function()
if am >= 0 then
if db == false then
db = true
am = am -1
local hum = plr.Character.Humanoid
if hum ~= nil then
al = hum:LoadAnimation(pr.FireAnim)
al:Play()
end
if m.Target ~= nil then
rs:FireServer(m.Hit.Position,false)
else
rs:FireServer(m.Hit.Position,true)
end
wait(0.25)
db = false
end
else
if db == false then
db = true
local hum2 = plr.Character.Humanoid
if hum2 ~= nil then
al1 = hum2:LoadAnimation(pr.ReloadAnim)
al1:Play()
end
pr.Mag.Transparency = 1
pr.Reload:Play()
pr.Bolt.Position = pr.Handle.BoltAttach2.Position
wait(1)
am = am +17
db = false
pr.Mag.Transparency = 0
pr.Bolt.Position = pr.Handle.BoltAttach1.Position
end
end
end)
pr.Equipped:Connect(function()
local hum1 = plr.Character.Humanoid
if hum1 ~= nil then
al = hum1:LoadAnimation(pr.IdleAnim)
al:Play()
end
end)
pr.Unequipped:Connect(function()
local hum1 = plr.Character.Humanoid
if hum1 ~= nil then
al = hum1:LoadAnimation(pr.IdleAnim)
al:Stop()
end
end)
Server script:
local plrs game:GetService("Players")
local tws = game:GetService("TweenService")
local pr = script.Parent
local rs = game.ReplicatedStorage.Shot
local gr = 500
local dm = pr.Damage
local la = nil
rs.OnServerEvent:Connect(function(plr, ms, tr)
pr.Fire:Play()
pr.Bolt.Position = pr.Handle.BoltAttach2.Position
if pr == nil then return end
local drb = (ms - pr.Bolt.Position) * gr
local rcp = RaycastParams.new()
rcp.FilterDescendantsInstances = {plr.Character}
rcp.FilterType = Enum.RaycastFilterType.Blacklist
local rs1 = workspace:Raycast(pr.Bolt.Position, drb, rcp)
local bl = game.ServerStorage.Bullet:Clone()
bl.CFrame = pr.Bolt.CFrame
bl.Parent = game.Workspace
local bld = 0.3 * ((drb/gr).Magnitude)/50
tws:Create(bl, TweenInfo.new(bld), {CFrame = CFrame.new(ms)}):Play()
if not tr then
task.delay(bld,function()
bl:Destroy()
end)
else
task.delay(1, function()
bl:Destroy()
end)
end
if rs1 == nil then return end
local h = rs1.Instance.Parent:FindFirstChild("Humanoid")
if h ~= nil then return end
task.wait(bld)
h.Health -= dm
pr.Bolt.Position = pr.Handle.BoltAttach1.Position
end)
Have a nice day!