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

Make this script run again on character respawn?

Right now, this script only runs when the player enters, then never runs again. I want to make it run again when the player respawns, but I'm not sure how I would go to doing this.

local wings = game.ReplicatedStorage.Wings
local mps = game:GetService("MarketplaceService")

game:GetService("Players").PlayerAdded:Connect(function(player)
    if mps:UserOwnsGamePassAsync(player.UserId,5260848) then
        local function createMachine()
            local wingsClone = wings:Clone()
            wingsClone.PrimaryPart = wingsClone.Base
            wingsClone.Parent = player.Character
            wingsClone:moveTo(player.Character.Torso.Position)

            local weld = Instance.new("Motor6D")
            weld.Parent = wingsClone.Base
            weld.Part0 = wingsClone.Base
            weld.Part1 = player.Character.Torso
        end
        createMachine(player)
    end
end)

4 comments

0

Just make it Touched function, and add it to the Spawn Point, it will do it always when he touches the spawn point.

0

just use the CharacterAdded event of the player, which fires when the character loads or respawns

0

How would I go to applying that to this script? I tried multiple ways, but it's only a event of player so it's kind of difficult to do

1 answer

✓ Accepted answer

Use the CharacterAdded Event.


local wings = game.ReplicatedStorage.Wings
local mps = game:GetService("MarketplaceService")


game:GetService("Players").PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
   	 	if mps:UserOwnsGamePassAsync(player.UserId,5260848) then
      	 	 local function createMachine()
          	 local wingsClone = wings:Clone()
           	 wingsClone.PrimaryPart = wingsClone.Base
         	 wingsClone.Parent = player.Character
                  wingsClone:moveTo(player.Character.Torso.Position)

            	local weld = Instance.new("Motor6D")
            	weld.Parent = wingsClone.Base
            	weld.Part0 = wingsClone.Base
            	weld.Part1 = player.Character.Torso
        	end
        	createMachine(player)
    	end
end)
end)

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