Dear Devforum,
I’ve been creating a Fife similar to B&I and G&B’s Fife however it doesn’t seem to work as I thought it would:
MODULE:
local Fife = {}
Fife.__index = Fife
function Fife.New(player : Player, tool : Tool)
local self = setmetatable({}, Fife)
self.Tool = tool
self.Handle = self.Tool:WaitForChild("Handle")
self.Event = self.Tool:WaitForChild("Event")
self.State = nil
print(self.State)
self.Character = player.Character
self.Animator = self.Character:WaitForChild("Humanoid").Animator
self.Animations = self.Tool:WaitForChild("Animations")
self.IdleAnimation = self.Animator:LoadAnimation(self.Animations:WaitForChild("Idle"))
self.SelectedSong = nil
return self
end
local function PlayAnimation(v : Animation)
if v then
v:Play()
else
warn("Animation does not exist.")
end
end
local function StopAnimation(v : Animation)
if v then
v:Stop()
else
warn("Animation does not exist.")
end
end
function Fife:Activate(v : Sound)
if self.SelectedSong then
self.SelectedSong = v
self.SelectedSong:Play()
else
warn("No song selected.")
end
self.State = "Playing"
print(self.State)
PlayAnimation(self.IdleAnimation)
end
function Fife:Deactivate()
if self.SelectedSong then
self.SelectedSong:Stop()
else
warn("No song selected.")
end
self.State = nil
print(self.State)
StopAnimation(self.IdleAnimation)
end
return Fife
LOCAL SCRIPT:
--Services:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local Players = game:GetService("Players")
--Modules:
local Fife_Handler = require(ReplicatedStorage.Modules:WaitForChild("Fife_Handler"))
--Variables:
local Player = Players.LocalPlayer
local Tool = script.Parent
local Audio = Tool:FindFirstChild("Music")
Tool.Equipped:Connect(function()
Fife_Handler.New(Player, Tool)
end)
Tool.Activated:Connect(function()
Fife_Handler:Activate(Audio.Fife_1)
end)
Tool.Unequipped:Connect(function()
Fife_Handler:Deactivate()
end)
ERRORS: