This collection of scripts makes the correct bodyparts visible, plays an animation, then fires a raycast and slows down whatever got hit. When I run it, it works fine. But when other people in my team create session run it, the animations are broken and the raycast doesn't fire. Why could this be happening?
Localscript to play animation and fire server event:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local humanoid = script.Parent:FindFirstChild("Humanoid")
local ammo = script:WaitForChild("Ammo")
local barrel = humanoid.Parent.AnimPistol:WaitForChild("Barrel")
local grip = humanoid.Parent.AnimPistol.GAssembly:WaitForChild("Grip")
local trigger = humanoid.Parent.AnimPistol.GAssembly:WaitForChild("Trigger")
local gun = humanoid.parent.AnimPistol
local arm = humanoid.Parent:WaitForChild("Right Arm")
barrel.Transparency = 1
grip.Transparency = 1
trigger.Transparency = 1
local origin = script.Parent.AnimPistol.Barrel
local bFolder = game.Workspace.Bullets
local bulletFiredEvent = game.ReplicatedStorage.bulletFired
barrel.PointLight.Enabled = false
local canShoot = false
local coolDown = true
local keyBind = "f"
local mouse = player:GetMouse()
mouse.TargetFilter = bFolder
mouse.KeyDown:Connect(function(key)
if key == keyBind then
if ammo.Value ~= 0 and coolDown == true then
canShoot = true
end
if canShoot == true then
canShoot = false
coolDown = false
local animation = humanoid:LoadAnimation(script.Animation)
animation:Play()
local function antiTransGun(part)
if part and part:IsA("BasePart") and (part == barrel or part == grip or part == trigger) then
part.LocalTransparencyModifier = part.Transparency
part.Changed:connect(function (property)
part.LocalTransparencyModifier = part.Transparency
end)
end
end
for _,v in pairs(gun:GetChildren()) do
antiTransGun(v)
end
arm.LocalTransparencyModifier = 0
barrel.Transparency = 0
grip.Transparency = 0
trigger.Transparency = 0
animation:GetMarkerReachedSignal("Cock"):Connect(function()
--play cocking sound
end)
animation:GetMarkerReachedSignal("GunShot"):Connect(function()
barrel.PointLight.Enabled = true
barrel.Attachment.Flash.Enabled = true
barrel.Attachment.Smoke.Enabled = true
local mousePosition = mouse.Hit.p
local originPosition = origin.Position
bulletFiredEvent:FireServer(mousePosition, originPosition)
for i = 0, 3 do
local zoom = math.random(70, 90)
workspace.Camera.FieldOfView = zoom
wait()
workspace.Camera.FieldOfView = 70
end
--play shoot sound
end)
animation:GetMarkerReachedSignal("UnFlash"):Connect(function()
barrel.Attachment.Flash.Enabled = false
barrel.PointLight.Enabled = false
end)
animation.Stopped:Connect(function()
barrel.Attachment.Smoke.Enabled = false
arm.LocalTransparencyModifier = 1
barrel.Transparency = 1
grip.Transparency = 1
trigger.Transparency = 1
end)
ammo.Value -= 1
wait(5)
coolDown = true
end
end
end)
Regular script that handles the raycast
local bulletFiredEvent = game.ReplicatedStorage.bulletFired
local bulletFolder = game.Workspace.Bullets
local debris = game:GetService("Debris")
local range = 999
local function createBeam(origin, direction)
local midpoint = (origin + direction / 2)
local part = Instance.new("Part")
part.Parent = bulletFolder
part.Anchored = true
part.CanCollide = false
part.Material = Enum.Material.Plastic
part.BrickColor = BrickColor.new("Black")
part.CFrame = CFrame.new(midpoint, origin)
part.Size = Vector3.new(.075, .075, direction.magnitude)
for i = 0.75, 1, .01 do
part.Transparency = i
wait(.1)
end
debris:AddItem(part, 3)
end
bulletFiredEvent.OnServerEvent:Connect(function(player, mousePos, originPos)
local direction = (mousePos - originPos).Unit * range
local result = workspace:Raycast(originPos, direction)
if result then
local character = result.Instance.Parent
local humanoid = character:FindFirstChild("Humanoid")
if humanoid and humanoid ~= player.Character.Humanoid then
humanoid.WalkSpeed = 2
wait(5)
humanoid.WalkSpeed = 16
end
end
createBeam(originPos, direction)
end)
Note that the animation is not created by the group, but rather by myself. Uploading it to the group makes it wonky. I'm trying to figure out why I'm the only person that can get it to work.

1 comment
Commit the script