I’m trying to save the Player’s weapon when they die and have it Equip when the player spawns in after. I’ve been trying to save a Value into StarterCharacterScripts, but the Value does not change and just prints “-”. Any clue why?
local Players = game:GetService(“Players”)
local function onPlayerAdded(player)
local function onCharacterAdded(character)
local Sword = character.Sword.Value
local humanoid = character:WaitForChild(“Humanoid”)
print(Sword)
local function onDied()
local Sword = character.Sword
local Tool = character:FindFirstChildOfClass("Tool")
Sword.Value = tostring(Tool)
end
humanoid.Died:Connect(onDied)
end
player.CharacterAdded:Connect(onCharacterAdded)
local remoteToGiveWeapon = remote
Humanoid.Died:Connect(function()
local Tool = --define tool here
local toolName = Tool.Name
remoteToGiveWeapon:FireServer(toolName)
end)
server script
--- you can add some security so player will not be able to spam with remote
--not sure but if it won't work try to add CharacterAdded INSIDE function
remote.OnServerEvent(player, toolName)
local toolName = tostring(toolName)
for i,v in pairs(folderWithTool:FindFirstChild(toolName)
if i.Name == toolName then
i:Clone().Parent = player.Backpack
end
end
end)
Hmm your local script is successful in communicating what tool the player died with, however in the server script I’m getting the error “invalid argument #1 to ‘pairs’ (table expected, got Instance)” for the parameter I put (game.ServerScriptStorage.ShopItems:FindFirstChild(toolName)) “ShopItems” being the folder. Any ideas?