Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
3ora 54
5 years ago
Edited 5 years ago

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()
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. xPolarium 1388 — 5y
0
Because the tool breaks if I don't use the remote event. 3ora 54 — 5y
0
Also, it's a remote event not a remote function.. 3ora 54 — 5y
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? SerpentineKing 3885 — 5y
View all comments (6 more)
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. 3ora 54 — 5y
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. 3ora 54 — 5y
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. 3ora 54 — 5y
0
i understand that, im wondering if only the four specified people are supposed to get a boombox or whatev SerpentineKing 3885 — 5y
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 3ora 54 — 5y
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. 3ora 54 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
0
I will test it now. 3ora 54 — 5y
0
Thanks! It works now. 3ora 54 — 5y
Ad

Answer this question