Hi, im making a simple beam attack similar to spirit gun
The beam raycast itself works fine but when I try to play an animation with it, whenever the arm moves up, the characters body breaks, example here https://gyazo.com/1ba93aec9b127d29a9457ffd2e1cc532
Any help towards this would be appreciated
-- Local script
local player = game.Players.LocalPlayer
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://8617066696"
Animation.Parent = script.Parent--Where you want to store the animation
local Character = player.Character or player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local anim = Humanoid:LoadAnimation(Animation)
local mouse = player:GetMouse()
local Staff = script.Parent
local Core = Staff.Core
local FireEvent = Staff:WaitForChild("Fire")
local CoolDown = 1.5
local Debounce = false
Staff.Activated:Connect(function()
if Debounce then return end
anim:Play()
wait(0.10)
Debounce = true
FireEvent:FireServer(mouse.Hit.p)
wait(CoolDown)
Debounce = false
end)
-- Server Script
local Staff = script.Parent
local Core = Staff:WaitForChild("Core")
local FireEvent = Staff:WaitForChild("Fire")
local Range = script.Range.Value
FireEvent.OnServerEvent:Connect(function(player, hitPos)
if hitPos then
local ray = Ray.new(Core.Position, (hitPos - Core.Position).Unit * Range)
local part, position = workspace:FindPartOnRay(ray, Staff.Parent)
local C = script.Parent.Core:Clone()
C.Parent = workspace
C.Anchored = true
C.CanCollide = false
local beam = Instance.new("Part", Staff)
beam.Name = "Beam"
beam.BrickColor = Core.BrickColor
beam.Material = Enum.Material.Neon
beam.Transparency = 0.3
beam.Anchored = true
beam.CanCollide = false
local dist = (Staff.Core.Position - position).magnitude
beam.Size = Vector3.new(.5, .5, dist)
beam.CFrame = CFrame.new(Core.Position, position) * CFrame.new(0, 0, -dist / 2)
if part and part.Parent:FindFirstChild("Humanoid") then
part.Parent.Humanoid:TakeDamage(10)
end
beam.Size = Vector3.new(0.45, 0.45, dist)
for i = 1,7 do
wait(0.05)
beam.Size = beam.Size - Vector3.new(0.05, 0.05, 0)
beam.Transparency = beam.Transparency + 0.1
C.Transparency = C.Transparency + 0.1
end
C:Destroy()
beam:Destroy()
end
end)