Hello, I am currently trying to make it so that when a player presses J, they do a hands raised animation, and their backpack saves and clears, and then gives gives back the items when they click J again.
I have worked out the animation part, so the script is going to have unrelated things, but I just need help on the parts with comments.
(note that I got help on this script, and don’t 100% understand it)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Backpack = game:GetService(game.Players.PlayerName.Backpack)
local Surrender = ReplicatedStorage:WaitForChild("Surrender")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://15687971905"
local surrenderedPlayers = {}
local surrenderAnimations = {}
Surrender.OnServerEvent:Connect(function(player)
local humanoid = player.Character and player.Character:FindFirstChildWhichIsA("Humanoid")
if not humanoid then
return
end
local hasSurrendered = surrenderedPlayers[player]
if hasSurrendered then
surrenderedPlayers[player] = false
else
surrenderedPlayers[player] = true
end
if surrenderedPlayers[player] then
local surrenderAnimation = humanoid.Animator:LoadAnimation(animation)
surrenderAnimation:Play()
surrenderAnimations[player] = surrenderAnimation
-- Save and then clear backpack
else
surrenderAnimations[player]:Stop()
-- Give items back
end
end)
Players.PlayerAdded:Connect(function(player)
player.CharacterRemoving:Connect(function()
surrenderedPlayers[player] = nil
surrenderAnimations[player] = nil
end)
end)
I know that I have to use the dictionary to save it, but thats about it.