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

Why isn't my clone going into workspace? Its not even cloning.

Everything is working except for line 9 and 10. I've looked at the output and nothing. I've used the print statement and that didn't help either. Please help me.

script.Parent.RedFlag.Handle.Touched:Connect(function(char) 
    if char ~= nil then 
        local player = game.Players:GetPlayerFromCharacter(char.Parent) 
        if player then--check if they are a player
            if char.Parent:FindFirstChild("Humanoid") then 
                if char.Parent.Humanoid.Health ~= 0 then--if they are still alive
                    print(player.Name .. " has the Red Flag!")
            if char.Parent:FindFirstChild("Humanoid").Health == 0 and char.Parent:FindFirstChild("RedFlag") then--if they die and they have the flag
							 local FlagClone = game:GetService("ServerStorage"):WaitForChild("RedFlag"):Clone()--the flag gets cloned and put into workspace
                            FlagClone.Parent = game.Workspace 
            		end                                      
                end
            end
        end
    end
wait(2)
end)

1 answer

✓ Accepted answer

The problem here is that your if statement is not returning as true and the code contained within it (lines 09 and 10) are not running at all. This is because this check only runs once, when they touch the flag itself. To detect that someone has died you will need to use events. Carousing the documentation here, I see that there is an event called Died. Let's use that in your code.

-- your code ...
print(player.Name .. " has the Red Flag!")
char.Parent:FindFirstChild("Humanoid").Died:Connect(function())
    if char.Parent:FindFirstChild("RedFlag") then --if they die and they have the flag
        local FlagClone = game:GetService("ServerStorage"):WaitForChild("RedFlag"):Clone()--the flag gets cloned and put into workspace
        FlagClone.Parent = game.Workspace 
    end                                      
end
-- more of your code

5 comments

0

I will try this and I will get back to you asap

0

So all you did was replace my line 8 with your line 3?

0

Kind of. I replaced your if statement with an event connection and moved your if statement down.

0

Ok

0

I just tested it out and it works! Thank you so much!! I've been trying to fix this problem forever! Thank you!

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