Hey there!
I am currently making a game, and it has tools that require animations. But the problem is that the animations aren’t loading/working. These tools are saved in a datastore so when the player leaves, all their tools will be in the inventory but the animations dont load or work, the animations work fine when i give them to myself using the dev console just not after being saved with the datastore.
There are no output errors.
Here is the animation script:
local Player = game.Players.LocalPlayer
local character = Player.Character
local Animation = script.Parent:FindFirstChild("Idle")
local SwingAnimation = script.Parent:FindFirstChild("SwingAnimation")
local Equipped = false
local canSwing = true
repeat wait() until character
local CharacterAnim = character.Humanoid:LoadAnimation(Animation)
local CharacterSwingAnim = character.Humanoid:LoadAnimation(SwingAnimation)
script.Parent.Equipped:Connect(function()
if Equipped == false then
CharacterAnim:Play()
Equipped = true
end
end)
script.Parent.Unequipped:Connect(function()
if Equipped == true and CharacterAnim.IsPlaying == true then
CharacterAnim:Stop()
Equipped = false
end
end)
script.Parent.Activated:Connect(function()
if canSwing == true then
CharacterSwingAnim:Play()
character.Humanoid.WalkSpeed = 0
canSwing = false
wait(2.1)
canSwing = true
character.Humanoid.WalkSpeed = 16
end
end)
The Datastore script:
-- This script works fine, it properly saves the current tools in the Players backpack and Starter Gear
local DataStoreService = game:GetService("DataStoreService")
local savedTools = DataStoreService:GetDataStore("ToolData")
local toolsFolder = game.ServerStorage.Tools
game.Players.PlayerAdded:Connect(function(plr)
local toolsSaved = savedTools:GetAsync(plr.UserId.."-tools") or {}
for i, toolSaved in pairs(toolsSaved) do
if toolsFolder:FindFirstChild(toolSaved) then
toolsFolder[toolSaved]:Clone().Parent = plr.Backpack
toolsFolder[toolSaved]:Clone().Parent = plr.StarterGear
end
end
plr.CharacterRemoving:Connect(function(char)
char.Humanoid:UnequipTools()
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
local ownedTools = {}
for i, toolInBackpack in pairs(plr.Backpack:GetChildren()) do
table.insert(ownedTools, toolInBackpack.Name)
end
local success, errormessage = pcall(function()
savedTools:SetAsync(plr.UserId.."-tools", ownedTools)
end)
if errormessage then warn(errormessage) end
end)
The datastore script was taken from GamerM8’s simulator tutorial.
Thanks for the help!