Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[ANSWERED] How do I make the died event run more than once?

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()

10 comments

0

Why do you need the RemoteFunction? Note that a RemoteFunction is used to get a response back from where you're communicating to, this case from the server.

0

Because the tool breaks if I don't use the remote event.

0

Also, it's a remote event not a remote function..

0

Quick question as im going through this, the second part pertaining to the humanoid death is supposed to occur for all players or just the 4 owners?

0

Also note that I have tried using a loop, it just spams me with lots of boomboxes. There is probably another method to use looping but i'm not too skilled at scripting.

0

The player argument gets the player who is running the script (player who joined the game), so it's supposed to occur for the player who has just joined.

0

the LocalScript is in ReplicatedFirst, so it runs when the player joins the game to check if their username is any of those 4.

0

i understand that, im wondering if only the four specified people are supposed to get a boombox or whatev

0

Yes, only the four specified people are supposed to get it, but only at once since it checks for each player who joins the server

0

Say if me (3ora) joined the game, I would get the boombox since the name matches. If my name was "Shedletsky" the remote event would fire but do nothing since the name is not whitelisted.

1 answer

✓ Accepted answer

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)

2 comments

0

I will test it now.

0

Thanks! It works now.

This discussion is preserved as it was. New answers, comments, and votes are closed.