People, I am seriously losing my mind right now.
I am creating a lil practically still animation of the character holding the gun and it is literally not working, I have no idea why.
when I run .IsPlaying
on the animation track, it returns True
, however I do not see it.
What I have tried: This is a group game so I set the creation owner of as according the group. Before this, since it was still, I thought of using welds and CFrame rotations/orientations to move the left Arm so I can try and just have it next to the gun but I abandoned it half way, should I go back to it and if so, how should I tackle it.
Here is the LocalScript
of the gun:
local userInputService = game:GetService(“UserInputService”)
local LaserRenderer = require(game.StarterPlayer.StarterPlayerScripts.LaserRenderer)
local replicatedStorage = game:GetService(“ReplicatedStorage”)
local targetDamageEvent = game.ReplicatedStorage.Events.TargetRegistry
local partTargetDamageEvent = game.ReplicatedStorage.Events.TargetHitEvent
local laserRenderEvent = game.ReplicatedStorage.Events.LaserRendering
local targetFolder = workspace.TargeFolder
local player = game:GetService(“Players”).LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local tool = script.Parent
local muzzle = tool:WaitForChild(“Muzzle”)
local ammo = 30
local clipSize = ammo
local holdAnimation = Instance.new(“Animation”, tool)
holdAnimation.AnimationId = “rbxassetid://12802793658”
local animator = humanoid:FindFirstChildOfClass(“Animator”)
local animationTrack = animator:LoadAnimation(holdAnimation)
local pressed = userInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
local reload = false
local maxMouseRange = 1000
local maxRayRange = 999
local function getMouseLocation()
local mouseLocation = userInputService:GetMouseLocation()
local screenToWorldRay = workspace.CurrentCamera:ViewportPointToRay(mouseLocation.X, mouseLocation.Y) – This part uses the x and y axis of the 2d mouse data in order to get a ray of where it is pointing at.
local directionVector = screenToWorldRay.Direction * maxMouseRange
local raycastResult = workspace:Raycast(screenToWorldRay.Origin, directionVector)
if raycastResult then
return raycastResult.Position
else
return screenToWorldRay.Origin + directionVector
end
end
local function equip()
– Positioning of the weapon to be held by 2 hands
--tool.Handle.Parent = character.LeftHand + character.RightHand
tool.Handle.Equip:Play() -- Equip SFX
animationTrack:Play()
print(animationTrack.IsPlaying)
end
local function reloadFunc()
reload = true
tool.Name = “[REL]”
tool.Handle.Reload:Play()
task.wait(4.5)
clipSize = 30
reload = false
tool.Name = “[”…clipSize…“]”
end
local function reloadAction(key, gameProcessedEvent)
if key.KeyCode == Enum.KeyCode.R and reload == false and clipSize < ammo then
reloadFunc()
end
end
local function activate()
if clipSize == 0 then
if reload == true then
else
reloadFunc()
end
else
pressed = userInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
while pressed and task.wait(0.13) and reload == false and clipSize > 0 do
tool.Handle.Activate:Play()
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {player.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local mousePointer = getMouseLocation()
local targetDirectionVector = (mousePointer - muzzle.Position).Unit * maxRayRange
local raycastResult = workspace:Raycast(muzzle.Position, targetDirectionVector, raycastParams)
local raycastResultIndex = 0
if raycastResult then
local hitPosition = raycastResult.Position
local contactModel = raycastResult.Instance.Parent
raycastResultIndex += 1
if contactModel then
local humanoid = contactModel:FindFirstChild("Humanoid")
if humanoid then
targetDamageEvent:FireServer(humanoid)
laserRenderEvent:FireServer(muzzle.Position, hitPosition)
elseif contactModel == targetFolder then
for _, target in targetFolder:GetChildren() do
if raycastResult.Instance == target then
partTargetDamageEvent:FireServer(target)
else
end
end
end
else
local hitPosition = muzzle.Position + targetDirectionVector
laserRenderEvent:FireServer(muzzle.Position, hitPosition)
end
LaserRenderer.createLaser(muzzle.Position, hitPosition)
else
local hitPosition = muzzle.Position + targetDirectionVector
laserRenderEvent:FireServer(muzzle.Position, hitPosition)
LaserRenderer.createLaser(muzzle.Position, hitPosition)
end
pressed = userInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
clipSize -= 1
tool.Name = "["..clipSize.."]"
if clipSize == 0 then
reloadFunc()
end
end
end
end
local function unequipped()
pressed = false
animationTrack:Stop()
end
local function renderServerSideLasers(shootingPlayer, originPosition, endPosition)
if shootingPlayer ~= player then
LaserRenderer.createLaser(originPosition, endPosition)
end
end
tool.Equipped:Connect(equip)
userInputService.InputBegan:Connect(reloadAction)
tool.Activated:Connect(activate)
tool.Unequipped:Connect(unequipped)
laserRenderEvent.OnClientEvent:Connect(renderServerSideLasers)
Serverside and laser rendering all works fine and are not part of the problem, however they follow the system in the ROBLOX guide as it is noted to be the most efficient (other than the laser rendering which was purely for beginnner creation)
Prerequisite information: R6 model, All parts are welded to the Arm as it is like an RCL gun. All parts of the gun are held together with qPerfectionWeld script. I use ToolGrip editor from a guy who has goose
in his name. P.S: Yes, the animation is already set on loop.
Basically what I am asking: how can I get the animation to work where the animation is a simple rotation of the other hand so it is holding the gun, either via CFrame rotation or animation, thank you and sorry if this was not a very clear topic, please give some replies for clarification or how I can improve this topic.