I am working on a backrooms game, when i made the flashlight, the animation dont seem to animate correctly on the first time, its kinda wierd and getting annoying, i don’t know why thats happening
Flashlight Local Script:
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character
local Assets = ReplicatedStorage.Assets
local Events = ReplicatedStorage.Events
LocalPlayer.CharacterAdded:Connect(function(NewCharacter)
Character = NewCharacter
end)
local Keys = {
Enum.KeyCode.F,
Enum.KeyCode.ButtonX
}
local Debounce = true
UserInputService.InputBegan:Connect(function(Key)
for i,v in pairs(Keys) do
if Key.KeyCode == v and Debounce == true and LocalPlayer.Character.CanFlashlight.Value == true then
Debounce = false
Events.Flashlight:FireServer(LocalPlayer)
wait(1)
Debounce = true
end
end
end)
Flashlight Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Assets = ReplicatedStorage.Assets
local Events = ReplicatedStorage.Events
Animation = nil
Events.Flashlight.OnServerEvent:Connect(function(Player)
if Player.Character:FindFirstChild("FlashlightPart") then
local NewSound = Player.Character.FlashlightPart.Value.Off:Clone()
NewSound.Parent = Player.Character.Head
NewSound:Play()
Player.Character.FlashlightPart.Value:Destroy()
Player.Character.FlashlightPart:Destroy()
Animation:Stop()
Animation = nil
wait(1)
else
local FlashlightPart = Player.Character:FindFirstChild("Right Arm")
local Attachment = Instance.new("Attachment")
Attachment.Parent = FlashlightPart
Attachment.Position = Vector3.new(0,-FlashlightPart.Size.Y/2,0)
Attachment.Orientation = Vector3.new(90,0,0)
local NewFlashlight = Assets.Flashlight:Clone()
NewFlashlight.Parent = workspace
NewFlashlight.CFrame = Attachment.WorldCFrame
local ObjectValue = Instance.new("ObjectValue")
ObjectValue.Parent = Player.Character
ObjectValue.Name = "FlashlightPart"
ObjectValue.Value = NewFlashlight
local NewSound = NewFlashlight.Click:Clone()
NewSound.Parent = Player.Character.Head
NewSound:Play()
local Weld = Instance.new("WeldConstraint")
Weld.Parent = FlashlightPart
Weld.Part0 = FlashlightPart
Weld.Part1 = NewFlashlight
local NewAnimation = Player.Character.Humanoid:LoadAnimation(script.FlashlightAnimation)
NewAnimation.Priority = Enum.AnimationPriority.Action4
NewAnimation:Play()
wait(NewAnimation.Length - 0.1)
NewAnimation:AdjustSpeed(0)
Animation = NewAnimation
end
end)