I made this script that gives a player an item when bought with in-game currency. The way it works is when the player has enough coins and clicks the "Buy" button the game clones a tool from ReplicatedStorage to the players StarterGear, backpack.
local player = game.Players.LocalPlayer
local leaderboard = player:WaitForChild("leaderstats")
local button = script.Parent
local price = button:WaitForChild("Price")
local item = button:WaitForChild("ItemName")
local rs = game:GetService("ReplicatedStorage")
button.MouseButton1Click:connect(function()
if leaderboard.Coins.Value >= price.Value then
leaderboard.Coins.Value = leaderboard.Coins.Value - price.Value
local item = rs:WaitForChild(item.Value)
item:Clone().Parent = player.StarterGear
item:Clone().Parent = player.Backpack
end
end)
while wait() do
button.image = item.Value.." - "..price.Value
end
For some reason when the tool is moved the animations in the tool stop working. Here is the Animations script:
local function WaitForChild(parent, childName)
while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
return parent[childName]
end
local Tool = script.Parent
local Animations = {}
local MyHumanoid
local MyCharacter
local function PlayAnimation(animationName)
if Animations[animationName] then
Animations[animationName]:Play()
end
end
local function StopAnimation(animationName)
if Animations[animationName] then
Animations[animationName]:Stop()
end
end
function OnEquipped(mouse)
MyCharacter = Tool.Parent
MyHumanoid = WaitForChild(MyCharacter, 'Humanoid')
if MyHumanoid then
Animations['EquipAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'EquipAnim5'))
Animations['IdleAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'IdleAnim3'))
Animations['OverheadAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'OverheadAnim2'))
Animations['SlashAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'SlashAnim2'))
Animations['ThrustAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'ThrustAnim2'))
Animations['UnequipAnim'] = MyHumanoid:LoadAnimation(WaitForChild(Tool, 'UnequipAnim2'))
end
PlayAnimation('EquipAnim')
PlayAnimation('IdleAnim')
end
function OnUnequipped()
for animName, _ in pairs(Animations) do
StopAnimation(animName)
end
end
Tool.Equipped:connect(OnEquipped)
Tool.Unequipped:connect(OnUnequipped)
WaitForChild(Tool, 'PlaySlash').Changed:connect(
function (value)
PlayAnimation('SlashAnim')
end)
WaitForChild(Tool, 'PlayThrust').Changed:connect(
function (value)
PlayAnimation('ThrustAnim')
end)
WaitForChild(Tool, 'PlayOverhead').Changed:connect(
function (value)
PlayAnimation('OverheadAnim')
end)
If anyone knows why the animations break when the tool is moved to StarterGear it will help me a ton. Thanks!

4 comments
(Also just wanted to add. When I test it out in Studio it works but not in game. And yes the Animations Script and the Purchase Script are Local)
maybe try refreshing the script, by setting the Disabled to true then wait() to false
and also why it doesn't work online is probably, because of FE, which has a bunch of remote events and stuff
and u cant turn it off