Need help with Cloning a model using a command

Hello DevFourm, I am trying to code a script that will spawn a golf cart next to you. I am not sure what I am doing wrong. Please help.

Code (its in serverscriptservice)

game.Player.PlayerAdded:Connect(function (player)
	player.Chatted:Connect(function(msg)
		if msg == "!spawn cart" then
			if player.GetRoleInGroup(10968280) >= 240 then
				local clone = game.ReplicatedStorage.GolfCart:Clone()
				clone.Parent = workspace
				clone.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame + Vector3.new (5, 0, 0)
			else
				print("sorry u cant spawn cart noob")
		end
	end)
end)

Developer Logs Ingame

!

Replacted Storage [Where the cart is stored]
Screen Shot 2021-07-26 at 8.51.55 AM|186x78

Thanks,
Kazok

1 Like

As the error states, Position is not a valid memeber of the folder. This code doesn’t appear to be requesting the position of anything. Is this error from another script?

There is no end closing the if statement.

You forgot to put End at the 2 if Statement

game.Player.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "!spawn cart" then
			if player.GetRoleInGroup(10968280) >= 240 then
				local clone = game.ReplicatedStorage.GolfCart:Clone()
				clone.Parent = workspace
				clone.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame + Vector3.new (5, 0, 0)
			else
				print("sorry u cant spawn cart noob")
			end
		end
	end)
end)

Um I tried that and it did not work.

Yes. I was a bit confused at first. But now Im confused that why did my script not run?

Would it not be player:GetRoleInGroup()?

Now try and tell me if this will print anything in the output

game.Player.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "!spawn cart" then
			if player.GetRoleInGroup(10968280) >= 240 then
				print("Car has spawned")
				local clone = game.ReplicatedStorage.GolfCart:Clone()
				clone.Parent = workspace
				clone.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame + Vector3.new (5, 0, 0)
			else
				print("sorry u cant spawn cart noob")
			end
		end
	end)
end)

ohhhhhhhhhhhhh. bigbrain. thanks i will try

nope. still nothing. maybe ill try removing the group.

just tried that. it did not work. maybe there is something wrong with the script?

okay i found the issue.

here is the new script:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "!spawn cart" then
			if player:IsInGroup(10968280) then                    
				if player:GetRankInGroup(10968280) >= 240 then
					print("cart has spawned")
					local clone = game.ReplicatedStorage.GolfCart:Clone()
					clone.Parent = workspace
					clone.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame + Vector3.new (5, 0, 0)
				else
					print("sorry u cant spawn cart noob")
				end
			else
				print("player is not in group!")
			end
		end
	end)
end)

ok thx. i think it is working. ty.

1 Like

it spawned. but i dont know where it is. i think its because the HumanoidRootPart is from a dummy because that is what i based the script out of. is there a way to teleport the golf cart next to you?

1 Like

Try this:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "!spawn cart" then
			if player:IsInGroup(10968280) then                    
				if player:GetRankInGroup(10968280) >= 240 then
					print("cart has spawned")
					local clone = game.ReplicatedStorage.GolfCart:Clone()
					clone.Parent = workspace
					clone.CFrame = player.Character.HumanoidRootPart.CFrame + Vector3.new (5, 0, 0)
				else
					print("sorry u cant spawn cart noob")
				end
			else
				print("player is not in group!")
			end
		end
	end)
end)

You accidentally put HumanoidRootPart.CFrame on the golf cart that’s why it’s position was never moved

I wasn’t the one who put this
See his original script

Oh ok well anyways that’s why it’s not spawning in the right spot sorry about that

ok this will work now

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if msg == "!spawn cart" then
			if player:IsInGroup(10968280) then                    
				if player:GetRankInGroup(10968280) >= 240 then
					print("cart has spawned")
					
					local Pos = player.Character.PrimaryPart.Position
					local newPos = Vector3.new(Pos.X + 5,Pos.Y ,Pos.Z) 
					
					local clone = game.ReplicatedStorage.GolfCart:Clone()					
					clone:PivotTo(clone.PrimaryPart.CFrame:Lerp(newPos, Pos, 1))
					clone.Parent = workspace

				else
					print("sorry u cant spawn cart noob")
				end
			else
				print("player is not in group!")
			end
		end
	end)
end)

Or just without the HumanoidRootPart on the golf cart should work and be simpler

Why own a golf cart on HumanoidRootPart ?