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)
local FnfFolder = ReplicatedStorage.FnfArrows
local arrow = ReplicatedStorage.FnfArrows.Arrow:Clone()
local arrowsId = { FnfFolder.BlueMesh:Clone(),
FnfFolder.GreenMesh:Clone(),
FnfFolder.PurpleMesh:Clone(),
FnfFolder.RedMesh:Clone()
}
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?
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?