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 cloned object printing it's parent?

I wanted to make a clone of the flag when the player dies with it, but nothing is printing. Except for line 7, but not line 11. Please help me if you can. Thanks.

script.Parent.RedFlag.Handle.Touched:Connect(function(char) 
    if char ~= nil then 
        local player = game.Players:GetPlayerFromCharacter(char.Parent) 
        if player ~= nil then 
            if char.Parent:FindFirstChild("Humanoid") then 
                if char.Parent:FindFirstChild("Humanoid").Health ~= 0 then 
                    print(player.Name .. " has the Red Flag!")
						if char.Parent:FindFirstChild("Humanoid").Health == 0 and char.Parent:FindFirstChild("RedFlag")then
							local FlagClone = game.ServerStorage:FindFirstChild("RedFlag"):Clone()
							FlagClone.Parent = game.Workspace
							print(FlagClone.Parent)							
					end                    
                end
            end
        end
    end
wait(1)
end)

2 answers

✓ Accepted answer

You cannot print an object. If you wanted to print the name, you can do

print(FlagClone.Parent.Name)

or you could do

print(FlagClone.Parent:GetFullName())

to get the full name. Hope this helps!

Edit A possible reason the clone has not been created, is that the service was not created yet using GetService. To fix this, you can do

local FlagClone = game:GetService('ServerStorage').RedFlag:Clone()
FlagClone.Parent = workspace

Otherwise, I do not know why it would not be cloning.

4 comments

0

Ok thanks

0

But, do you know why my clone isn't showing up in Workspace? It's not even printing the name. If you can't help, its totally fine.

0

Ill just make it another question for other people to answer if you can't.

0

Try my edit.

local debounce = false
print("Not touched yet")
script.Parent.RedFlag.Handle.Touched:Connect(function(char) 
    if char and debounce == false  then 
	print("Touched")
	debounce = true
        if game.Players:GetPlayerFromCharacter(char.Parent)  then 
		 local player = game.Players:GetPlayerFromCharacter(char.Parent) 
            if char.Parent:FindFirstChild("Humanoid") then 
                if char.Parent:FindFirstChild("Humanoid").Health > 0 then  -- Checks if humanoid health is more than 0, if you put in ~= the value could be a negative, to fix this we have to do > 0
                    print(player.Name .. " has the Red Flag!")
                      	     char:FindFirstChild("Humanoid").Died:Connect(function() -- We use the humanoid.Died event to see when the humanoid dies
                            local FlagClone = game:GetService("ServerStorage"):FindFirstChild("RedFlag"):Clone()
                            FlagClone.Parent = game:GetService("Workspace")
                            print(FlagClone.Parent.Name) -- We cannot print objects, we can get the name of the object(The name of the object is inside a string)
			end)                        
                end
			else
				return print("Humanoid is nil")
            end
		else
			return print("Player is nil")
        end
	   else
		return print("Character is nil") -- I put return because I want to make sure there cannot be anything after the print function
    end
wait(1)
if debounce == true then
	debounce = false
end
end)

If this has answered you question, please accept

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