Setting the parent property of a parent

he means humanoid health

Well, your parenting thing might work, I cant try since I’m on mobile, however it’s not good to have a script in every single coin anyways

Yes however if he sets the Humanoid.Health to 0 they would die, which why would they die when they collect a coin?

Why do I have to add characters to a post referencing another post as a response? Anyway, I just beat the character limit by asking myself deep questions about it.

Oh sorry I didn’t see that part, I’m either blind or it didn’t load.

You can select a random coin like maybe try this script:

local coinsFolder = game.Workspace.Map.Coins:GetChildren()
local inactiveCoins = game.Workspace.Map.InactiveCoins:GetChildren()

for i=1,#coinsFolder do
    local coin = coinsFolder[i]
    if not coin:IsA("BasePart") then continue end
    coin.Touched.Connect(function(hit)
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then
            if i % 4 == 0 then
                player.Character.Humanoid.Health = 0
            else
                -- Add coins
            end
            coin.Parent = inactiveCoins
        end
    end
end

Explenation:

  1. Get variables for the folder
  2. Loop through using for i=1 loop
  3. Get the coin using coinsFolder[i]
  4. Set up a touch event
  5. Make sure a player hit the part
  6. Check if the remainder of i/4 == 0
  7. Decide to add coins or to kill player

I’m so confused right now. I just tested it in a fresh new baseplate instead of my actual game and it works. I don’t understand why it’s acting differently on my game.

Update: I got it working. I don’t know what I did wrong first, but instead a new part of the script is not working. I’m talking about this:

local originalparent = script.Parent

restart.OnServerEvent:Connect(function()
	script.Parent.Parent = originalparent
end)

Other things happen in between these two parts (you can see the full script in the original post), but the originalparent variable is set at the beginning of the script, before moving it to the inactive folder.

I have switched all coin management to one script by suggestion of @domboss37. I have limited this to only coin management as different traps have different specific executions. I would also like to apologize to @Qinrir for all the confusion. I don’t know what was causing it to not work only in my specific game I’m working on, but it has now been fixed. Thank you all for contributing to a great solution!