I am trying to make a script that makes a certain item stay in your inventory after dying.
But I don’t know how I would do this since this is an item that you can pickup.
I have tried looking it up but it hasn’t helped.
Script to pickup the item
local ToolNames = {"SCP-178", "Item", "Item"}
local Storage = game:GetService("ServerStorage")
local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
local Debounce = false
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if player and player.Character and not Debounce then
local Backpack = player.Backpack
for i = 1, #ToolNames do
local Tool = Storage:FindFirstChild(ToolNames[i])
if Tool then
local Tool = Tool:Clone()
Tool.Parent = Backpack
local gui = Instance.new("ScreenGui",player.PlayerGui)
local textlabel = Instance.new("TextLabel",gui)
local tweenService = game:GetService("TweenService")
workspace.pickitem2:Play()
textlabel.Size = UDim2.new(0, 482,0, 46)
textlabel.BackgroundTransparency = 1
textlabel.BorderSizePixel = 0
textlabel.TextColor3 = Color3.new(1, 1, 1)
textlabel.Font = "SpecialElite"
textlabel.Position = UDim2.new(0.362, 0,0.734, 0)
textlabel.TextSize = "20"
textlabel.Text = "You picked up SCP-178"
textlabel.TextTransparency = 0
local timeToFade = 5
local object = textlabel
local tweenInfo = TweenInfo.new(timeToFade)
local goal = {
['TextTransparency'] = 1
}
local tween = tweenService:Create(object,tweenInfo, goal)
tween:Play()
workspace["3D Glasses"].Transparency = 1
Debounce = true
end
end
end
end)
script.Parent.ClickDetector.RightMouseClick:Connect(function(player)
if player and player.Character and Debounce then
local Backpack = player:WaitForChild("Backpack")
for i = 1, #ToolNames do
local Tool = Storage:FindFirstChild(ToolNames[i])
if Tool then
local gui = Instance.new("ScreenGui",player.PlayerGui)
local textlabel = Instance.new("TextLabel",gui)
local tweenService = game:GetService("TweenService")
workspace.pickitem2:Play()
textlabel.Size = UDim2.new(0, 482,0, 46)
textlabel.BackgroundTransparency = 1
textlabel.BorderSizePixel = 0
textlabel.TextColor3 = Color3.new(1, 1, 1)
textlabel.Font = "SpecialElite"
textlabel.Position = UDim2.new(0.362, 0,0.734, 0)
textlabel.TextSize = "20"
textlabel.Text = "You Placed SCP-178"
textlabel.TextTransparency = 0
local timeToFade = 5
local object = textlabel
local tweenInfo = TweenInfo.new(timeToFade)
local goal = {
['TextTransparency'] = 1
}
local tween = tweenService:Create(object,tweenInfo, goal)
tween:Play()
workspace["3D Glasses"].Transparency = 0
Debounce = false
Backpack:WaitForChild("SCP-178",1):Destroy()
end
end
end
end)
I would make a script in ServerScriptService that checks for when a character dies, checks their inventory for the item and if they have it, wait until they respawn to give it to them again.
In my opinion, to do this, first I would create a Folder inside of ReplicatedStorage, clone the item into the Folder when the player dies, check when the player respawns, get the item from the folder and clone it back into the player.
Created a tool-saver script for you., so let me know if anything goes wrong.
Local Script (goes into starterplayerscripts)
Forgot one more thing, Add a Folder into replicatedStorage for this to work
local player = game:GetService("Players").LocalPlayer
repeat task.wait() until player.Character
local char = player.Character
local humanoid = char:WaitForChild("Humanoid")
local savefolder = game:GetService("ReplicatedStorage").Folder
local save = savefolder:GetChildren()
humanoid.Died:Connect(function()
print(player.Name .. " is dead")
for _, tools in pairs(char:GetDescendants()) do
if tools:IsA("Tool") then
local clones = tools:Clone()
clones.Parent = savefolder
end
end
print(#save)
player.CharacterAdded:Connect(function()
print(player.Name .. " is back")
for _, addBacks in ipairs(savefolder:GetDescendants()) do
if addBacks:IsA("Tool") then
local addbackclones = addBacks:Clone()
addbackclones.Parent = player.Backpack
-- folder reset --
task.wait(.1)
savefolder:ClearAllChildren() -- // Remove this for actual tool-saving results.
end
end
end)
end)
How about the script, is it inside of StarterPlayerScripts?
if it is then it might be the script you are using to pick up the item maybe
I have also updated my script a bit. Here you go:
local player = game:GetService("Players").LocalPlayer
repeat task.wait() until player.Character
local char = player.Character
local humanoid = char:WaitForChild("Humanoid")
local savefolder = game:GetService("ReplicatedStorage").Folder
local save = savefolder:GetChildren()
humanoid.Died:Connect(function()
print(player.Name .. " is dead")
for _, tools in pairs(player.Backpack:GetDescendants()) do
if tools:IsA("Tool") then
local clones = tools:Clone()
clones.Parent = savefolder
end
end
for _, tools in pairs(char:GetDescendants()) do
if tools:IsA("Tool") then
local clones = tools:Clone()
clones.Parent = savefolder
end
end
print(#save)
player.CharacterAdded:Connect(function()
print(player.Name .. " is back")
for _, addBacks in pairs(savefolder:GetDescendants()) do
if addBacks:IsA("Tool") then
local addbackclones = addBacks:Clone()
addbackclones.Parent = player.Backpack
-- folder reset --
task.wait(.1)
savefolder:ClearAllChildren() -- Remove this for actual tool-saving results.
end
end
end)
end)
oh
would you like the grab script i made to grab tools? (touch them to collect)
It probably is the script to pick it up because it clones the tool and adds the clone to the player’s backpack. But if you right click the same place, it puts it back into the same spot.
local ToolNames = {"SCP-178", "Item", "Item"}
local Storage = game:GetService("ServerStorage")
local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
local Debounce = false
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if player and player.Character and not Debounce then
local Backpack = player:WaitForChild("Backpack")
for i = 1, #ToolNames do
local Tool = Storage:FindFirstChild(ToolNames[i])
if Tool then
Tool:clone().Parent = Backpack
local gui = Instance.new("ScreenGui",player.PlayerGui)
local textlabel = Instance.new("TextLabel",gui)
local tweenService = game:GetService("TweenService")
workspace.pickitem2:Play()
textlabel.Size = UDim2.new(0, 482,0, 46)
textlabel.BackgroundTransparency = 1
textlabel.BorderSizePixel = 0
textlabel.TextColor3 = Color3.new(1, 1, 1)
textlabel.Font = "SpecialElite"
textlabel.Position = UDim2.new(0.362, 0,0.734, 0)
textlabel.TextSize = "20"
textlabel.Text = "You picked up SCP-178"
textlabel.TextTransparency = 0
local timeToFade = 5
local object = textlabel
local tweenInfo = TweenInfo.new(timeToFade)
local goal = {
['TextTransparency'] = 1
}
local tween = tweenService:Create(object,tweenInfo, goal)
tween:Play()
workspace["3D Glasses"].Transparency = 1
Debounce = true
end
end
end
end)
script.Parent.ClickDetector.RightMouseClick:Connect(function(player)
if player and player.Character and Debounce then
local Backpack = player:WaitForChild("Backpack")
for i = 1, #ToolNames do
local Tool = Storage:FindFirstChild(ToolNames[i])
if Tool then
local gui = Instance.new("ScreenGui",player.PlayerGui)
local textlabel = Instance.new("TextLabel",gui)
local tweenService = game:GetService("TweenService")
workspace.pickitem2:Play()
textlabel.Size = UDim2.new(0, 482,0, 46)
textlabel.BackgroundTransparency = 1
textlabel.BorderSizePixel = 0
textlabel.TextColor3 = Color3.new(1, 1, 1)
textlabel.Font = "SpecialElite"
textlabel.Position = UDim2.new(0.362, 0,0.734, 0)
textlabel.TextSize = "20"
textlabel.Text = "You Placed SCP-178"
textlabel.TextTransparency = 0
local timeToFade = 5
local object = textlabel
local tweenInfo = TweenInfo.new(timeToFade)
local goal = {
['TextTransparency'] = 1
}
local tween = tweenService:Create(object,tweenInfo, goal)
tween:Play()
workspace["3D Glasses"].Transparency = 0
Debounce = false
Backpack:WaitForChild("SCP-178",1):Destroy()
end
end
end
end)
I am not very into scripting yet though so if there is something that I could change then you can just tell me.
local ToolNames = {"SCP-178", "Item", "Item"}
local Storage = game:GetService("ServerStorage")
local Part = script.Parent
local ClickDetector = Part:WaitForChild("ClickDetector")
local Debounce = false
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if player and player.Character and not Debounce then
local Backpack = player.Backpack
for i = 1, #ToolNames do
local Tool = Storage:FindFirstChild(ToolNames[i])
if Tool then
local tool = Tool:Clone()
Tool.Parent = Backpack
local gui = Instance.new("ScreenGui",player.PlayerGui)
local textlabel = Instance.new("TextLabel",gui)
local tweenService = game:GetService("TweenService")
workspace.pickitem2:Play()
textlabel.Size = UDim2.new(0, 482,0, 46)
textlabel.BackgroundTransparency = 1
textlabel.BorderSizePixel = 0
textlabel.TextColor3 = Color3.new(1, 1, 1)
textlabel.Font = "SpecialElite"
textlabel.Position = UDim2.new(0.362, 0,0.734, 0)
textlabel.TextSize = "20"
textlabel.Text = "You picked up SCP-178"
textlabel.TextTransparency = 0
local timeToFade = 5
local object = textlabel
local tweenInfo = TweenInfo.new(timeToFade)
local goal = {
['TextTransparency'] = 1
}
local tween = tweenService:Create(object,tweenInfo, goal)
tween:Play()
workspace["3D Glasses"].Transparency = 1
Debounce = true
end
end
end
end)
script.Parent.ClickDetector.RightMouseClick:Connect(function(player)
if player and player.Character and Debounce then
local Backpack = player:WaitForChild("Backpack")
for i = 1, #ToolNames do
local Tool = Storage:FindFirstChild(ToolNames[i])
if Tool then
local gui = Instance.new("ScreenGui",player.PlayerGui)
local textlabel = Instance.new("TextLabel",gui)
local tweenService = game:GetService("TweenService")
workspace.pickitem2:Play()
textlabel.Size = UDim2.new(0, 482,0, 46)
textlabel.BackgroundTransparency = 1
textlabel.BorderSizePixel = 0
textlabel.TextColor3 = Color3.new(1, 1, 1)
textlabel.Font = "SpecialElite"
textlabel.Position = UDim2.new(0.362, 0,0.734, 0)
textlabel.TextSize = "20"
textlabel.Text = "You Placed SCP-178"
textlabel.TextTransparency = 0
local timeToFade = 5
local object = textlabel
local tweenInfo = TweenInfo.new(timeToFade)
local goal = {
['TextTransparency'] = 1
}
local tween = tweenService:Create(object,tweenInfo, goal)
tween:Play()
workspace["3D Glasses"].Transparency = 0
Debounce = false
Backpack:WaitForChild("SCP-178",1):Destroy()
end
end
end
end)
i made the tool:Clone.Parent line into a variable maybe it might work now
It didn’t change and it also prevented me from placing it back.
so I don’t what else could be stopping it.
The only other thing that messes around with inventory and stuff is the custom inventory gui
I’m sorry if this is completely wrong, but why not simply just put it into the Player’s Starter Gear and the backpack? Putting it into the backpack lets you use it at first, and when you kick the bucket, startgear will clone it back to your backpack.