Hello everyone, i want to make a script that gives a player a tool into the starter pack after a few seconds it should vanish from the players backpack again.
i Scripted a little bit of the script that should do it for me but i’m sadly having an issue that i dont know how to fix it myself “attempt to index with 'Backpack’”
game.ServerStorage.Snowball.Parent = game.StarterPack
wait(15)
local player = game:GetService("player")
local Request = "Snowball"
if player.Backpack:FindFirstChild(Request) and player.Backpack[Request]:IsA("Tool") then
player.Backpack.Snowball:Destroy()
end
if player.Character and player.Character:FindFirstChild(Request) and player.Character[Request]:IsA("Tool") then
player.Character[Request]:Destroy()
end
Also Thanks to @Awesom3_Eric for having the Script on the Dev Forun.
Please help me solve my problem and i would be very grateful hopefully we can learn something together!
game.ServerStorage.Snowball.Parent = game.StarterPack
game:GetService("Players").PlayerAdded:Connect(function(player)
wait(15)
local Request = "Snowball"
if player.Backpack:FindFirstChild(Request) and player.Backpack[Request]:IsA("Tool") then
player.Backpack.Snowball:Destroy()
end
if player.Character and player.Character:FindFirstChild(Request) and player.Character[Request]:IsA("Tool") then
player.Character[Request]:Destroy()
end
end)
Your initial problem:
player is not an existing service. To fetch a player, you would use this instead:
local player = game:GetService("Players")["username here"]
You can also use functions and connections that provide the player as a parameter, such as PlayerAdded and PlayerRemoving:
game:GetService("Players").PlayerAdded:Connect(function(player)
--code here
end)
Update: Again Help needed the scripts and everything works but the tool is in the starter pack and doesn’t seem to appear anymore for some sort of reason but it did work before.
no i have other issues everything works its even in the Starterpack but it doesn’t seem to apear in the inventory. i use 2. scripts 1. script holds all the events because it dosent seem to work directly in the event script i made it activate the other script wich does everthing right but it doesent seem to apear in the inventory but it did work before.
Script 1.
elseif event == 4 then
workspace.General.Map.Material = Enum.Material.Sand
workspace.General.Map.Color = Color3.new(1, 1, 1)
game.Workspace.GiveSnowball.Enabled = true
wait(30)
workspace.General.Map.Material = Enum.Material.Grass
workspace.General.Map.Color = Color3.new(0.356863, 0.603922, 0.298039)
end
end
end)
Script 2.
game.ServerStorage.Snowball.Parent = game.StarterPack
wait(30)
game:GetService("Players").PlayerAdded:Connect(function(player)
local Request = "Snowball"
if player.Backpack:FindFirstChild(Request) and player.Backpack[Request]:IsA("Tool") then
player.Backpack.Snowball:Destroy()
end
if player.Character and player.Character:FindFirstChild(Request) and player.Character[Request]:IsA("Tool") then
player.Character[Request]:Destroy()
end
end)
Thats simply because you’re waiting 30 seconds before the PlayerAdded event connects!
If you want to pause the execution, just move that line into the event’s function.
Or
you can do that but after this line just put a for loop to iterate between the existing players But are you sure you want to make the script to pause for the first time running?