So, my friend wanted to script his game and wanted me to make a script which clones a boombox from ServerStorage to player.Backpack on the server, this is my code. I have a remote function in Replicated Storage called "Owner Give"
game.ReplicatedStorage["Owner Give"].OnServerEvent:Connect(function(player) local ServerStorage = game:GetService("ServerStorage") if player.Name == "Waffleszx" then ServerStorage["Owner Boom"]:Clone().Parent = player.Backpack end ----------- if player.Name == "3ora" then ServerStorage["Owner Boom"]:Clone().Parent = player.Backpack end ----------- if player.Name == "Ghxsst" then ServerStorage["Owner Boom"]:Clone().Parent = player.Backpack end ---------- if player.Name == "TUNDRAMANE" then ServerStorage["Owner Boom"]:Clone().Parent = player.Backpack end ---------- wait(0.1) -- this is the part where im struggling, how do i make this run every time player dies? if player.Backpack:FindFirstChild("Owner Boom") then player.Parent.Parent.Workspace[player.Name].Humanoid.Died:Connect(function() wait(5.7) ServerStorage["Owner Boom"]:Clone().Parent = player.Backpack end) end end)
I also have my LocalScript which is firing the remote in ReplicatedFirst.
wait(1) game.ReplicatedStorage["Owner Give"]:FireServer()
LocalScript
local player = game.Players.LocalPlayer repeat wait() until workspace:FindFirstChild(player.Name) ~= nil game.ReplicatedStorage["Owner Give"]:FireServer()
I added a longer wait time to make sure the player has a character
Variation of Above
local player = game.Players.LocalPlayer repeat wait() until player.Character ~= nil game.ReplicatedStorage["Owner Give"]:FireServer()
Server Script
local check = false local array = {"Waffleszx", "3ora", "Ghxsst", "TUNDRAMANE"} game.ReplicatedStorage["Owner Give"].OnServerEvent:Connect(function(player) local ServerStorage = game:GetService("ServerStorage") for i, v in pairs(array) do if player.Name == v then check = true end end if check == true then ServerStorage["Owner Boom"]:Clone().Parent = player.Backpack else -- Nothing end end)
This version uses a table for the players who get the Boombox. Upon testing, I found that a LocalScript in the StarterGui will automatically respawn the script, so it runs again, i.e. you don't actually need the Humanoid.Died
Event.
Below is a revised version of your previous script without using a table (but reducing the if-then clauses)
game.ReplicatedStorage["Owner Give"].OnServerEvent:Connect(function(player) local ServerStorage = game:GetService("ServerStorage") if player.Name == "Waffleszx" or player.Name == "3ora" or player.Name == "Ghxsst" or player.Name == "TUNDRAMANE" then ServerStorage["Owner Boom"]:Clone().Parent = player.Backpack end end)