(FIXED)Problems with cloning

Hello everyone. Im trying to make an AA gun. For that i need to clone a localscript from the model to the playerscritps, but tis not working.

The script:

wait(3)
local model = game.Workspace.AmericanBase.Cannons["Anti-Air1"]
local seat = model.Seat
local s = script.Parent.AA1

seat.Touched:Connect(function(touch)
	local c = touch.Parent:FindFirstChild("Humanoid")
	if c then
	wait(0.5)
	local player = game.Players:GetPlayerFromCharacter(c.Parent)
		print(player.Name)
		if player == true then
			if seat.Occupant ~= nil then
				print (seat.Occupant)
				local cl = s:Clone()
				local ps = player:FindFirstChild("PlayerScripts")
				cl.Parent = ps
				cl.Disabled = false
			end
		end
	end
end)

Thanks for reading.

1 Like

What’s the error? (30 Characters)

1 Like

There is no error. 30characters

1 Like

Does it print the player name and seat occupant?

1 Like

It prints the player, the seat occupant doesnt get printed.

1 Like

remove the “player == true” and see.

1 Like

It’s because of this line:

if player == true then

You’re comparing the Player object with a boolean value:

if player then
-- stuff
end

-- OR

if player ~= nil then
-- stuff
end
3 Likes

Player == true will NEVER be true since the Player is a Object More specificaly a Userdata not a boolean. Instead do
if Player then Since everything other than nil and false evaluate to true

3 Likes

script:

wait(3)
local model = game.Workspace.AmericanBase.Cannons["Anti-Air1"]
local seat = model.Seat
local s = script.Parent.AA1

seat.Touched:Connect(function(touch)
	local c = touch.Parent:FindFirstChild("Humanoid")
	if c then
	wait(0.5)
	local player = game.Players:GetPlayerFromCharacter(c.Parent)
		print(player.Name .."PlayerName")
			if seat.Occupant ~= nil then
				print (seat.Occupant .."Occupant")
				local cl = s:Clone()
				local ps = player:FindFirstChild("PlayerScripts")
				cl.Parent = ps
				cl.Disabled = false
		end
	end
end)

error:
image

1 Like

yes seat.Occupant is a object value and can’t be concatenated turn it to a string tostring(seat.Occupant) or seat.Occupant.Name (Which would return humanoid) You need to do .Parent to get the player.

1 Like

You are trying to do Seat.Occupant.." Occupant" but Seat.Occupant is a Player not a string instead do Seat.Occupant.Name

1 Like
wait(3)
local model = game.Workspace.AmericanBase.Cannons["Anti-Air1"]
local seat = model.Seat
local s = script.Parent.AA1

seat.Touched:Connect(function(touch)
	local c = touch.Parent:FindFirstChild("Humanoid")
	if c then
	wait(0.5)
	local player = game.Players:GetPlayerFromCharacter(c.Parent)
		print(player.Name .."PlayerName")
			if seat.Occupant ~= nil then
				print (tostring(seat.Occupant).."Occupant")
				local cl = s:Clone()
				local ps = player:FindFirstChild("PlayerScripts")
				cl.Parent = ps
				cl.Disabled = false
		end
	end
end)

Try that and tell me if it works.

2 Likes

Do NOT just give full script answers. This is against the rules of the #help-and-feedback:scripting-support category

2 Likes

you’re not meant to “spoon feed” scripts, the idea is to help people understand their problem.

2 Likes

output:
image

script:

wait(3)
local model = game.Workspace.AmericanBase.Cannons["Anti-Air1"]
local seat = model.Seat
local s = script.Parent.AA1

seat.Touched:Connect(function(touch)
	local c = touch.Parent:FindFirstChild("Humanoid")
	if c then
	wait(0.5)
	local player = game.Players:GetPlayerFromCharacter(c.Parent)
		print(player.Name .."PlayerName")
		if player ~= nil then
			if seat.Occupant ~= nil then
				print (tostring(seat.Occupant) .."Occupant")
				local cl = s:Clone()
				local ps = player:FindFirstChild("PlayerScripts")
				cl.Parent = ps
				cl.Disabled = false
			end
		end
	end
end)

but still doesnt clone

1 Like

As I said, you need to do .Parent as the humanoid is the occupant.

1 Like

May I know why you are trying to parent that to PlayerScripts and not Workspace?

I need as much explanation as possible so I can try and help you fix this problem.

1 Like

output:
image

still not cloning

script:

wait(3)
local model = game.Workspace.AmericanBase.Cannons["Anti-Air1"]
local seat = model.Seat
local s = script.Parent.AA1

seat.Touched:Connect(function(touch)
	local c = touch.Parent:FindFirstChild("Humanoid")
	if c then
	wait(0.5)
	local player = game.Players:GetPlayerFromCharacter(c.Parent)
		print(player.Name .."PlayerName")
		if player ~= nil then
			if seat.Occupant ~= nil then
				print (tostring(seat.Occupant.Parent.Name) .."Occupant")
				local cl = s:Clone()
				local ps = player:FindFirstChild("PlayerScripts")
				cl.Parent = ps
				cl.Disabled = false
			end
		end
	end
end)
1 Like

As @Nerkonl You are parenting to “ps” which isn’t defined

1 Like

As I said, may I know why you are trying to parent “s” to PlayerScripts and not Workspace?

Additionaly can you please tell me what is “AA1”? I need more information regarding these stuff.

1 Like