Trying to clone SpecialMeshs random and into one Part

I am making one tool basicly every time I fire the function (Button1Down for shoot) the “arrow”(is basicly like one bullet) is cloned into the Workspace and the arrow isnt the same so I change it random. The arrow is one mesh and I want to change the meshId every time the RemoteEvent is fired

I tried to do something like this

	local arrowsId = { "rbxassetid://7273017666",
		               "rbxassetid://7273127922",
		               "rbxassetid://7273132162",
		               "rbxassetid://7272959637"
	                 }
	
	local arrow = ReplicatedStorage.FnfArrows.Arrow:Clone()
	
	local newMeshId 
	newMeshId = arrow.MeshId [math.random(1, #arrowsId)]

I dont get any erros on output. The mesh is cloned but the Id doesnt change.

full script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("FnfMicEvent")

RemoteEvent.OnServerEvent:Connect(function(player, gunPos, gunOr, mosPos)
	

	local arrowsId = { "rbxassetid://7273017666",
		               "rbxassetid://7273127922",
		               "rbxassetid://7273132162",
		               "rbxassetid://7272959637"
	                 }
	
	local arrow = ReplicatedStorage.FnfArrows.Arrow:Clone()
	
	local newMeshId 
	newMeshId = arrow.MeshId [math.random(1, #arrowsId)]
	
	
	local distance = (mosPos - gunPos).magnitude
	
	local speed = 200
	arrow.CFrame = CFrame.new(gunPos, mosPos)
	arrow.Velocity = arrow.CFrame.lookVector * speed
	
	local fly = Instance.new("BodyForce",arrow)
	fly.Force = Vector3.new(0, arrow:GetMass() * workspace.Gravity, 0)
	arrow.Orientation = gunOr + Vector3.new(0, -180, 0)	
	
	local attacker = Instance.new("StringValue")
	attacker.Name = "Attacker"
	attacker.Parent = arrow
	attacker.Value = player.Name
	
	local touchConnection = nil

	touchConnection = arrow.Touched:Connect(function()
		touchConnection:Disconnect()
	end)
end)

I think you have this backwards. Try:

arrow.MeshId = arrowsId[math.random(1,#arrowsId)]

1 Like

I am getting this issue.

You can’t change MeshId of MeshPart in runtime. If you want to do this use SpecialMesh instead.

So I have to use parts with the specialMesh?

Yes you are right, there isn’t unfortunately any other way to do it in runtime.

Ok I tried to do something like this:

    local FnfFolder = ReplicatedStorage.FnfArrows
	local arrow = ReplicatedStorage.FnfArrows.Arrow:Clone()
	
	local arrowsId = { FnfFolder.BlueMesh:Clone(),
		FnfFolder.GreenMesh:Clone(),
		FnfFolder.PurpleMesh:Clone(),
		FnfFolder.RedMesh:Clone()	
	}

image

Now I just have to do math.Random and change the Parent but I cant change the parent inside the table how I am gonna math random and change the meshs Parents for put inside the arrow?

I dont get any erros after this but I still have to try to do something for math Random this special meshs and change the Parent.

You can just have one SpecialMesh parented to the part and just change the MeshId of the SpecialMesh (even in runtime) with the random meshid.

but changing specialMeshId can give me that issue?

I suggested you using SpecialMesh over MeshPart because you can change its MeshId in runtime.

Using one specialMesh inside the meshPart works?

Give it a try and see if it works. :wink:

1 Like

Ok thats works I can just change the meshId and textureId too

One question why the math.Random doesnt change I mean the meshID is the same.(I only changed the TextureID bc the mesh is the same.)

sript:

local FnfFolder = ReplicatedStorage.FnfArrows
	local arrow = ReplicatedStorage.FnfArrows.Arrow:Clone()
	
	local arrowsTextureId = { "rbxassetid://7273017732",
		                      "rbxassetid://7273127980",
		                      "rbxassetid://7273132285",
		                      "rbxassetid://7272959703"
	                        }
	
	arrow.TextureID = arrowsTextureId[math.random(1,#arrowsTextureId)]

the arrow is one MeshPart

Great to hear that, make sure to mark my post as a solution so others can find it as well!

Can I see whole script please?

ok

script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("FnfMicEvent")

RemoteEvent.OnServerEvent:Connect(function(player, gunPos, gunOr, mosPos)
	
	local FnfFolder = ReplicatedStorage.FnfArrows
	local arrow = ReplicatedStorage.FnfArrows.Arrow:Clone()
	
	local arrowsTextureId = { "rbxassetid://7273017732",
		                      "rbxassetid://7273127980",
		                      "rbxassetid://7273132285",
		                      "rbxassetid://7272959703"
	                        }
	
	
	arrow.TextureID = arrowsTextureId[math.random(1,#arrowsTextureId)]
	
	arrow.Parent = game.Workspace
	arrow.Position = gunPos
	
	local distance = (mosPos - gunPos).magnitude
	
	local speed = 200
	arrow.CFrame = CFrame.new(gunPos, mosPos)
	arrow.Velocity = arrow.CFrame.lookVector * speed
	
	local fly = Instance.new("BodyForce",arrow)
	fly.Force = Vector3.new(0, arrow:GetMass() * workspace.Gravity, 0)
	arrow.Orientation = gunOr + Vector3.new(0, -180, 0)	
	
	local attacker = Instance.new("StringValue")
	attacker.Name = "Attacker"
	attacker.Parent = arrow
	attacker.Value = player.Name
	
	local touchConnection = nil

	touchConnection = arrow.Touched:Connect(function()
		touchConnection:Disconnect()
	end)
end)

It clones the problem is the TextureID doesnt change

Can you try to do something like this and show me what it printed.

local randId = arrowsTextureId[math.random(1,#arrowsTextureId)]
print("Random id is:",ranId)
arrow.TextureId = randId
print ("New texture id is:",arrow.TextureId)

Maybe try to set the SpecialMesh textureid instead?

1 Like

I am not using special mesh bc the mesh is the same I only want to change the texture.